After a SipEndpoint is created, an application must register the endpoint with the server before it can create or accept signaling sessions, send or receive messages, and be engaged in publication and subscription. SipEndpoint has been designed to register with Office Communications Server 2007.

Registering with a SIP Server Synchronously

Before calling Register to register a SipEndpoint, an application can override the default value for RegisterMethods. as in the following example.

Copy Code
endpoint.RegisterMethods = "Service,Notify,Benotify,Message,Info,Options";

The default value of RegisterMethods is the string "Service,Notify,Benotify,Message,Info,Options,Invite". Omitting Invite in the preceding example indicates to the server that the application does not intend to process incoming INVITE messages. Note that some messages are necessary for internal processing. For example, the server sends NOTIFY messages to the endpoint when the server is ready to unregister the endpoint. Applications normally use the default values of RegisterMethods unless they do not intend to receive page mode or INVITE messages.

The following example shows the synchronous pattern for registering a SipEndpoint object with a SIP registration server.

Copy Code
SipEndpoint endpoint = ...; // Created elsewhere
bool isRegistered = false;

try
{
   if (!isRegistered)
   {
	 endpoint.Register();
	 isRegistered = true;
   }
}

catch (RegisterException e)
{
   isRegistered = false;
   // Trace or handle a registration exception.
}
catch (AuthenticationException e)
{
   isRegistered = false;
   // Trace or handle an authentication exception.
}
catch (ConnectionFailureException e)
{
   isRegistered = false;
   // Trace or handle a connection exception.
}
catch (OperationTimeoutException e)
{
   isRegistered = false;
   // Trace or handle an operation timeout exception.
}

The following code example can be used in an application that intends to process INVITE messages for a user who is associated with multiple endpoints. The application can indicate that an INVITE message should be processed simultaneously at all endpoints. The server can fork INVITE messages to all endpoints only if all endpoints support this forking capability. Otherwise, the server might select one endpoint to which to send the INVITE message, ignoring the others. Endpoints that support forking must behave the same as other clients that support forking. Typically, such clients use presence information to determine whether to auto-accept, delay-accept, or seek user input in accepting incoming INVITE sessions. It is beyond the scope of this documentation to describe the forking behavior.

Copy Code
List<SignalingHeader> headers = new List<SignalingHeader>();
headers.Add(SignalingHeader.MicrosoftSupportedForking);
endpoint.Register(headers);

Registering with a SIP Server Asynchronously

The following example shows the asynchronous pattern for registering a SipEndpoint object.

Copy Code
try
{
	isRegistered = false;
	endpoint.BeginRegister(endpoint_RegisterComplete, endpoint);
}

catch (RegisterException e)
{
   isRegistered = false;
   // Trace or handle a registration exception.
}
catch (AuthenticationException e)
{
   isRegistered = false;
   // Trace or handle an authentication exception.
}
catch (ConnectionFailureException e)
{
   isRegistered = false;
   // Trace or handle a connection failure exception.
}
catch (OperationTimeoutException e)
{
   isRegistered = false;
   // Trace or handle an operation timeout exception.
}

The application implements the callback function, endpoint_RegisterComplete, to be invoked at the end of the asynchronous operation.

Copy Code
private void endpoint_RegisterComplete(IAsyncResult asyncResult)
{
  try
  {
	endpoint.EndRegister(asyncResult);
	isRegistered = true;
	// Application can raise an event here to inform the calling UI 
	// that the endpoint is now registered successfully.
  }

  catch (RegisterException e)
  {
	// Handle a registration exception according to application requirements.
  }

  catch (AuthenticationException e)
  {
	// Handle an authentication exception according to application requirements.
  }

  catch (ConnectionFailureException e)
  {
	isRegistered = false;
	// Trace or handle a connection failure exception.
  }
  catch (OperationTimeoutException e)
  {
	isRegistered = false;
	// Trace or handle an operation timeout exception.
  }
}

See Also

Other Resources

Creating a Real-Time Endpoint