How to Register
The UserAgentRegister contains an example of how to register a SIP account with a SIP Registrar.
The key snippet of the code is shown below with an explanation afterwards.
using System;
using SIPSorcery.SIP;
using SIPSorcery.SIP.App;
string USERNAME = "softphonesample";
string PASSWORD = "password";
string DOMAIN = "sipsorcery.com";
int EXPIRY = 120;
var sipTransport = new SIPTransport();
var regUserAgent = new SIPRegistrationUserAgent(sipTransport, USERNAME, PASSWORD, DOMAIN, EXPIRY);
regUserAgent.RegistrationFailed += (uri, err) => Console.WriteLine($"{uri.ToString()}: {err}");
regUserAgent.RegistrationTemporaryFailure += (uri, msg) => Console.WriteLine($"{uri.ToString()}: {msg}");
regUserAgent.RegistrationRemoved += (uri) => Console.WriteLine($"{uri.ToString()} registration failed.");
regUserAgent.RegistrationSuccessful += (uri) => Console.WriteLine($"{uri.ToString()} registration succeeded.");
regUserAgent.Start();
Explanation
The first step is to create a SIPTransport to allocate a transport layer that can be used to send and receive SIP requests and responses. The SIPTransport class supports a number of different protocols and is described in this article
var sipTransport = new SIPTransport();
Once the SIP transport is available a SIPRegistrationUserAgent can be created.
var regUserAgent = new SIPRegistrationUserAgent(sipTransport, USERNAME, PASSWORD, DOMAIN, EXPIRY);
Various events for the SIPRegistrationUserAgent can be subscribed to in order to track its operation.
regUserAgent.RegistrationFailed += (uri, err) => Console.WriteLine($"{uri.ToString()}: {err}");
regUserAgent.RegistrationTemporaryFailure += (uri, msg) => Console.WriteLine($"{uri.ToString()}: {msg}");
regUserAgent.RegistrationRemoved += (uri) => Console.WriteLine($"{uri.ToString()} registration failed.");
regUserAgent.RegistrationSuccessful += (uri) => Console.WriteLine($"{uri.ToString()} registration succeeded.");
The last step is to start the registration agent. This will cause the first registration attempt to occur and depending on the outcome will also schedule subsequent retries.
regUserAgent.Start();