Partilhar via


LocalEndpoint.BeginEstablish Method (AsyncCallback, Object)

Establishes the endpoint so that it can receive incoming calls and conference invitations.

Namespace:  Microsoft.Rtc.Collaboration
Assembly:  Microsoft.Rtc.Collaboration (in Microsoft.Rtc.Collaboration.dll)

Syntax

'Declaration
Public Function BeginEstablish ( _
    userCallback As AsyncCallback, _
    state As Object _
) As IAsyncResult
'Usage
Dim instance As LocalEndpoint
Dim userCallback As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginEstablish(userCallback, _
    state)
public IAsyncResult BeginEstablish(
    AsyncCallback userCallback,
    Object state
)

Parameters

  • userCallback
    Type: System.AsyncCallback
    The method to be called when the asynchronous operation is completed.
  • state
    Type: System.Object
    A user-provided object that distinguishes this particular asynchronous operation from other asynchronous operations.

Return Value

Type: System.IAsyncResult
An IAsyncResult that references the asynchronous operation.

Exceptions

Exception Condition
InvalidOperationException

Thrown when the state of the platform or endpoint is not correct for this operation.

Remarks

Registration, querying for in-band provisioning data, getting Media Relay Tokens, and automatic presence publication and subscription are some of the operations performed during endpoint establishment. For ApplicationEndpoints all the operations are optional while for UserEndpoints the last two operations are optional.

Examples

The following example shows how to establish an application endpoint. The example assumes that a CollaborationPlatform object has been started as a server platform. Application endpoints cannot be used with client platforms.

C# ApplicationEndpoint initialization

 
        try
        {
            ApplicationEndpointSettings settings = new ApplicationEndpointSettings("sip:myapplication@contoso.com");

            ApplicationEndpoint endpoint = new ApplicationEndpoint(platform, settings);

            // Customize settings if required
            settings.OwnerPhoneUri = "tel:+14255553333";

            // Register event handlers
            endpoint.StateChanged += this.Endpoint_StateChanged;
            endpoint.RegisterForIncomingCall<InstantMessagingCall>(this.InstantMessagingCallReceived);

            endpoint.BeginEstablish(this.EndpointEstablishCompleted, endpoint /*state*/);
        }
        catch (InvalidOperationException)
        {
            // Platform was shutdown on another thread

            // TODO: Replace with error handling code.
            Console.WriteLine("Could not establish endpoint. Platform was not in a valid state.");
        }

        private void EndpointEstablishCompleted(IAsyncResult result)
        {
            try
            {
                LocalEndpoint endpoint = result.AsyncState as LocalEndpoint;
                endpoint.EndEstablish(result);
            }
            catch (RealTimeException exception)
            {
                // TODO: Replace with error handling code.
                Console.WriteLine("Failed to establish endpoint: {0}", exception.Message);
            }
            finally
            {
                // TODO: Add clean up code here.

            }
        }

The following example shows how to establish an application endpoint. The example assumes that a CollaborationPlatform object has been started as a server platform. Application endpoints cannot be used with client platforms.

C# ApplicationEndpoint initialization

 
        try
        {
            UserEndpointSettings settings = new UserEndpointSettings(userName, serverName);

            // Customize settings if required
            settings.Credential = credential;

            UserEndpoint endpoint = new UserEndpoint(platform, settings);

            // Register event handlers
            endpoint.StateChanged += this.Endpoint_StateChanged;
            endpoint.RegisterForIncomingCall<InstantMessagingCall>(this.InstantMessagingCallReceived);

            endpoint.BeginEstablish(this.EndpointEstablishCompleted, endpoint /*state*/);
        }
        catch (InvalidOperationException)
        {
            // Platform was shutdown on another thread

            // TODO: Replace with error handling code.
            Console.WriteLine("Could not establish endpoint. Platform was not in a valid state.");
        }

        private void EndpointEstablishCompleted(IAsyncResult result)
        {
            try
            {
                LocalEndpoint endpoint = result.AsyncState as LocalEndpoint;
                endpoint.EndEstablish(result);
            }
            catch (RealTimeException exception)
            {
                // TODO: Replace with error handling code.
                Console.WriteLine("Failed to establish endpoint: {0}", exception.Message);
            }
            finally
            {
                // TODO: Add clean up code here.

            }
        }

See Also

Reference

LocalEndpoint Class

LocalEndpoint Members

BeginEstablish Overload

Microsoft.Rtc.Collaboration Namespace