Take a sneak peak of our new documentation Read More
Last Updated: 11/9/2022, 8:57:31 AM

# .NET (C#) SDK Getting Started Guide

# Overview

You can use AccelByte Cloud’s .NET (C#) SDK to implement our backend services within your game. The SDK acts as a bridge between your game and our services. This guide will show you how to create an application that uses .NET (C#) Server SDK from scratch.

# Prerequisites

# Tutorial

# Create a .NET (C#) Project

Create a new solution and a new console project inside the solution using dotnet CLI.

$ mkdir -p /path/to/mysolution
$ cd /path/to/mysolution
$ dotnet new sln --name mysolution      # Create a new solution: mysolution
$ dotnet new console -o myproject       # Create a new console project myproject
$ dotnet sln add myproject/myproject.csproj     # Add myproject to mysolution

# Add to Project Dependency

# From Repository

  1. Get a release version of the AccelByte C# Server SDK (opens new window) and add it as C# project dependency.

  2. Replace {VERSION} with a specific release version tag (opens new window).

    $ git clone https://github.com/AccelByte/accelbyte-csharp-sdk.git   # Clone AccelByte C# Server SDK
    $ cd accelbyte-csharp-sdk
    $ git checkout {VERSION}                                            # Switch to a specific release {VERSION}
    $ cp -rv AccelByte.Sdk /path/to/mysolution/AccelByte.Sdk            # Copy AccelByte C# Server SDK source code
    $ cd /path/to/mysolution
    $ dotnet sln add AccelByte.Sdk/AccelByte.Sdk.csproj             # Add AccelByte C# Server SDK to solution
    $ cd myproject
    $ dotnet add reference ../AccelByte.Sdk/AccelByte.Sdk.csproj    # Add AccelByte C# Server SDK as a dependency of C# project
    

    TIP

    We recommended using the .NET (C#) Server SDK version that matches your AccelByte Cloud version.

# Using Nuget

$ cd /path/to/mysolution/myproject # Go to project
$ dotnet add package AccelByte.Sdk # Add AccelByte C# Server SDK Package from Nuget

# Use in Code

  1. Create an SDK instance, log in using user credentials, and call an AccelByte Basic API in program.cs.

  2. The DefaultConfigRepository gets its values from AB_BASE_URL, AB_CLIENT_ID, and AB_CLIENT_SECRET environment variables.

    using System;
    using System.Collections.Generic;
    
    using AccelByte.Sdk.Core;
    using AccelByte.Sdk.Api;
    using AccelByte.Sdk.Api.Legal.Model;
    
    namespace AccelByteExample
    {
        internal class Program
        {
            static int Main(string[] args)
            {
                AccelByteSDK sdk = AccelByteSDK.Builder
                    .UseDefaultHttpClient()
                    .UseDefaultConfigRepository()
                    .UseDefaultTokenRepository()
                    .Build();
    
                bool login = sdk.LoginUser("myUsername", "myPassword");
                if (!login)
                {
                    Console.WriteLine("Login failed");
                    return 1;
                }
    
                try
                {
                    List<RetrieveAcceptedAgreementResponse>? response = sdk.Legal.Agreement.RetrieveAgreementsPublicOp.Execute();
                    if (response == null)
                        throw new Exception("Response is null");
    
                    foreach (var aggreement in response)
                        Console.WriteLine(aggreement.PolicyName);
                }
                catch (HttpResponseException e)
                {
                    Console.WriteLine(e.Message);
                    return 2;
                }
    
                bool logout = sdk.Logout();
                if (!logout)
                {
                    Console.WriteLine("Logout failed");
                    return 1;
                }
    
                return 0;
            }
        }
    }
    

# Run the Code

Set the required environment variables and run the code using dotnet run.

$ export AB_BASE_URL="https://demo.accelbyte.io"              # AccelByte Cloud Base URL e.g. demo environment
$ export AB_CLIENT_ID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"      # AccelByte Cloud OAuth Client ID
$ export AB_CLIENT_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"  # AccelByte Cloud OAuth Client Secret
$ cd /path/to/mysolution/myproject
$ dotnet run

# SDK Examples

See our .NET (C#) SDK example repo (opens new window) for a selection of test cases you can use to customize your game. You can also view the .NET (C#) Server SDK README.md (opens new window) for more information.

IAM

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Iam.Model;
using AccelByte.Sdk.Api.Iam.Operation;
using AccelByte.Sdk.Api.Iam.Wrapper;
Basic

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Basic.Model;
using AccelByte.Sdk.Api.Basic.Operation;
using AccelByte.Sdk.Api.Basic.Wrapper;
Social

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Social.Model;
using AccelByte.Sdk.Api.Social.Operation;
using AccelByte.Sdk.Api.Social.Wrapper;
Platform

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Platform.Model;
using AccelByte.Sdk.Api.Platform.Operation;
using AccelByte.Sdk.Api.Platform.Wrapper;
Group

API Docs (opens new window)

SDK reference (opens new window)

    using AccelByte.Sdk.Api.Group.Model;
    using AccelByte.Sdk.Api.Group.Operation;
    using AccelByte.Sdk.Api.Group.Wrapper;
Cloud Save

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Cloudsave.Model;
using AccelByte.Sdk.Api.Cloudsave.Operation;
using AccelByte.Sdk.Api.Cloudsave.Wrapper;
DSM Controller

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Dsmc.Model;
using AccelByte.Sdk.Api.Dsmc.Operation;
using AccelByte.Sdk.Api.Dsmc.Wrapper;
Session Browser

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Sessionbrowser.Model;
using AccelByte.Sdk.Api.Sessionbrowser.Operation;
using AccelByte.Sdk.Api.Sessionbrowser.Wrapper;
Lobby

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Lobby.Model;
using AccelByte.Sdk.Api.Lobby.Operation;
using AccelByte.Sdk.Api.Lobby.Wrapper;
Achievement

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Achievement.Model;
using AccelByte.Sdk.Api.Achievement.Operation;
using AccelByte.Sdk.Api.Achievement.Wrapper;
DS Log Manager

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Dslogmanager.Model;
using AccelByte.Sdk.Api.Dslogmanager.Operation;
using AccelByte.Sdk.Api.Dslogmanager.Wrapper;
UGC

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Ugc.Model;
using AccelByte.Sdk.Api.Ugc.Operation;
using AccelByte.Sdk.Api.Ugc.Wrapper;
Leaderboard

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Leaderboard.Model;
using AccelByte.Sdk.Api.Leaderboard.Operation;
using AccelByte.Sdk.Api.Leaderboard.Wrapper;
GDPR

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Gdpr.Model;
using AccelByte.Sdk.Api.Gdpr.Operation;
using AccelByte.Sdk.Api.Gdpr.Wrapper;
Legal

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Legal.Model;
using AccelByte.Sdk.Api.Legal.Operation;
using AccelByte.Sdk.Api.Legal.Wrapper;
Matchmaking

API Docs (opens new window)

SDK reference (opens new window)

using AccelByte.Sdk.Api.Matchmaking.Model;
using AccelByte.Sdk.Api.Matchmaking.Operation;
using AccelByte.Sdk.Api.Matchmaking.Wrapper;