none
SendSync and SendAsync methods RRS feed

  • Question

  • MessageSender SendSync and SendAsync methods behave in somewhat different manner. Is there some constraints to sending sync or async messages to Session.

    My second question is that what are the things to check while using sync method as I face problems to get return parameter from sync messages.

     

    Friday, March 2, 2007 10:27 AM

Answers

  • Hello - Yes the SendSync and SendAsync are designed to behave differently.  One of the primary objectives behind this was to make sure the developer who writes the code implicitly understands that a message is being sent could be destined to go across process boundary or machine boundary which is sitting across the world and there is a latency involved in it.  Besides that, this mechanism provides very simple mechanism to write code for it.

    Here is the example how you could write code to make a call synchronously.

     try {

     // Construct the message by creating header and body

       Message message = Message.CreateMessage(header, body);

     

     // Create an instance of the MessageSender to dispatch the message

     

       MessageSender messageSender = new MessageSender();

     

       CreateSessionResponse response = messageSender.SendSync<CreateSessionResponse>(message);

     

     // Response handling goes here.

     

    }

    catch (SoapFaultException<CreateRequestfault> ex) { 

     

      // Exception handling goes here.

     

    }

     

    *******************************************************************************

    Here is the example how you could write code to make a call Asynchronously.

     // Construct the message by creating header and body

       Message message = Message.CreateMessage(header, body);

     

     // Create an instance of the MessageSender to dispatch the message

     

       MessageSender messageSender = new MessageSender();

     

       messageSender.SendAsync(message);

     

    *******************************************************************************

    To receive an Asynchronous Response

    1.     Declare a public method

    2.     The method must accept a parameter of the response type

    3.     Add an operation tag to the method, including the operation name and the action of the response message

     

    [Operation(Name=“CreateSessionResponseOperation”, Action=SessionActions.CreateResponse, Oneway=true)]

    public void CreateSessionResponseHandler(CreateSessionResponse response)  

    {

       // Process the response here

       }

    Hope this provides enough contexts to understand how to use these methods.

     

    Regarding the question on Session, you could call all the Operations on Session both Sync & Async except the RouteMsgToParticipants as it is designed as ONEWAY method.  So you can call RouteMsgToParticipants ONLY Asynchronously.

     

     

    Thanks

     

    Tuesday, March 6, 2007 7:11 AM