Edit

Share via


ServerAgent Constructors

Definition

Overloads

ServerAgent(ApplicationManifest)

Simplified version of the constructor for use by script-only applications.

ServerAgent(Object, ApplicationManifest)

Creates a new server agent for the supplied application object and with the supplied application maifest.

ServerAgent(ApplicationManifest)

Simplified version of the constructor for use by script-only applications.

public:
 ServerAgent(Microsoft::Rtc::Sip::ApplicationManifest ^ manifest);
public ServerAgent (Microsoft.Rtc.Sip.ApplicationManifest manifest);
Public Sub New (manifest As ApplicationManifest)

Parameters

manifest
ApplicationManifest

Compiled application manifest.

Remarks

Note: This constructor should be used by applications that are only using a SIP Processing Language (MSPL) script in the application manifest for message processing. No calls to Dispatch should be present in the message filter script.In this case, the application serves solely to register the script with Lync Server 2013. No message processing is performed within the managed code application.

Two common exceptions that should be caught when calling this constructor:

  • ServerNotFoundException: Lync Server 2013 is not running.
  • UnauthorizedException: A connection to Lync Server 2013 could not be initialized. This is because of the current security context (user must be a member of the "Lync Server Users" local group), because the application has not been configured to run on this server, or because an application with the same URI (as specified in the application manifest) is already running.

Applies to

ServerAgent(Object, ApplicationManifest)

Creates a new server agent for the supplied application object and with the supplied application maifest.

public:
 ServerAgent(System::Object ^ app, Microsoft::Rtc::Sip::ApplicationManifest ^ manifest);
public ServerAgent (object app, Microsoft.Rtc.Sip.ApplicationManifest manifest);
Public Sub New (app As Object, manifest As ApplicationManifest)

Parameters

app
Object

Application object that implement dispatch handlers specified in the manifest. Additionally, the assembly containing the type of this object is searched for classes inheriting from built-in SIP classes, such as ServerTransaction. These classes are used whenever the SIP library needs to create a SIP object. This allows applications to maintain additional state with each SIP object. If an application wishes to take advantage of this feature, it should use the DefaultRTCClassAttribute attribute on the class definition.

manifest
ApplicationManifest

Compiled application manifest.

Exceptions

Server not running.

Server connection could not be initialized. This could be either because of the current security context (user must be a member of the "RTC Server Users" local group), because the application has not been configured to run on this server (through WMI), or because an application with the same URI is already running.

Other errors.

Remarks

This constructor is used by applications that receive messages dispatched from an MSPL script in the application manifest. The provided object implements the dispatch handlers for filtered messages.

A method used for handling specific dispatches is specified in the message filter script by calls to the MSPL built-in function Dispatch, passing the name of the method. Within the application, these methods must be implemented on a class, an instance of which is passed to this constructor. For example, if you have a call to Dispatch within the message filter script, as shown in the next example.

if (sipRequest) {
   Dispatch("OnRequestReceived");
}

As shown in the following example, you also need a corresponding method implemented in the application. Note that for request handlers, the function signature must match that of the RequestReceivedEventHandler delegate. For responses, the function signature must match that of the ResponseReceivedEventHandler delegate.

class MyRequestHandlers {
   ...
   public MyRequestHandlers() {
      // Constructor logic here
   }
   ...
   public void OnRequestReceived(object sender, RequestReceivedEventArgs rreArgs) {
      // Implement message handling behavior here
   }
   ...
}

With the class and the dispatch handlers implemented, you are able to call the constructor and create an instance of the ServerAgent class.

// First, create an instance of the class that contains the dispatch handlers.
MyRequestHandlers myHandlers = new MyRequestHandlers();

// Second, obtain and compile your application manifest.
ApplicationManifest myAppManifest = ApplicationManifest.CreateFromFile("C:\\xmldocs\\my_app_manifest_xml_file.xml");

try {

   myAppManifest.Compile();

}
catch (CompilerErrorException compilerErrorException) {

   Console.WriteLine("The following MSPL compiler errors occurred:");
   foreach (object errMsg in compilerErrorException.ErrorMessages)
   {
      Console.Write("\t{0}", errMsg.ToString());
   }
   Console.WriteLine();

}

// Now, create an instance of ServerAgent.
try {

   ServerAgent.WaitForServerAvailable(3); // Maximum 3 tries before failure
   ServerAgent myServerAgent = new ServerAgent(myHandlers, myAppManifest);

}
catch (UnauthorizedException ue) {

   Console.WriteLine("User is not authorized to connect to Lync Server: {0}", ue.ToString());

}
catch (ServerNotFoundException snfe) {

   Console.WriteLine("Lync Server not available: {0}", snfe.ToString());

}

The assembly containing the specified application object is searched for classes inheriting from built-in SIP classes, such as ServerTransaction. These classes are used whenever the SIP library needs to create a SIP object. This allows applications to maintain additional state with each SIP object. To take advantage of this feature, an application should use the [DefaultRTCClassAttribute] attribute on the class definition.

Two common exceptions that should be caught when calling this constructor:

  • ServerNotFoundException: Microsoft Lync Server 2013 is not running.
  • UnauthorizedException: A connection to Lync Server 2013 could not be initialized. This is because of the current security context (user must be a member of the "Lync Server Users" local group), because the application has not been configured to run on this server (through WMI), or because an application with the same URI (as specified in the application manifest) is already running.

Applies to