Dispatch
The Dispatchfunction dispatches an event to a supplied event handler within the application.
Syntax
Copy code | |
---|---|
bool Dispatch( string methodName, string value,... ); |
Parameters
Return values
Returns true if control was successfully transferred to the specified method; false if it was not. Failures can occur under heavy server loads.
Remarks
Within the application, there must be a method defined on the
object supplied to the
If your application is declared as script-only (such that the managed code component serves only to create a server agent instance and register your script), and you call Dispatch, compilation will fail. This is because a declaration of script-only implicitly informs the server that Dispatchwill never be called, assuming that you do not have any methods in the application to handle the messages.
A message is not dispatched if it has been previously dispatched, responded to, forked, or proxied. If an attempt is made to dispatch the message in one of these cases, a critical MSPL error is raised.
The Dispatchfunction has been extended to accept additional parameters that can specify references to any of the types defined above in the Parameters section. These new parameters are passed to the managed method as a params array of objects, where each object is a boxed based type (int, float, bool) or a string, depending on the type of the argument passed to the Dispatchfunction. The additional parameters may not specify any references to either the sipRequest or sipResponse built-in variables because the built-in variable state is already marshaled across.
Example code
Below is a code example showing the MSPL Dispatchcalls within the application manifest, and the corresponding event handler methods within the application itself.
Copy code | |
---|---|
<?xml version="1.0" ?> <lc:applicationManifest appUri="http://www.adatum.com/myApplicationLocation" xmlns:lc="http://schemas.microsoft.com/lcs/2006/05"> <lc:splScript><![CDATA[ if (sipRequest) { if (sipRequest.Method == StandardMethod.Invite) { Dispatch("OnInvite"); } else if (sipRequest.Method == StandardMethod.Message) { Dispatch("OnMessage"); } } ]]></lc:splScript> </lc:applicationManifest> ... public void OnInvite (object sender, RequestReceivedEventArgs requestArgs) { // INVITE request processing goes here. } public void OnMessage (object sender, RequestReceivedEventArgs requestArgs) { // MESSAGE request processing goes here. } ... |