locked
Calling ICalculator asynchronously from a Workflow RRS feed

  • Question

  • Taken straight from the WCF 4.0 RC samples:

     

        [ServiceContract(Namespace = "http://Microsoft.Samples.Asynchronous")]

        public interface ICalculator

        {

            [OperationContract]

            double Add(double n1, double n2);

     

            [OperationContract]

            double Subtract(double n1, double n2);

     

            //Multiply involves some file I/O so we'll make it Async.

            [OperationContract(AsyncPattern = true)]

            IAsyncResult BeginMultiply(double n1, double n2, AsyncCallback callback, object state);

            double EndMultiply(IAsyncResult ar);

     

            //Divide involves some file I/O so we'll make it Async.

            [OperationContract(AsyncPattern = true)]

            IAsyncResult BeginDivide(double n1, double n2, AsyncCallback callback, object state);

            double EndDivide(IAsyncResult ar);

        }

     

     

    How can I call the BeginMultiply or BeginDivide async operations from a workflow?

    Is there a way to do it with native messaging activities (Send/Receive etc)?

    Or do I need to use a WCF client wrapped in an Async Code activity or similar?

     

    Thanks!

    Thursday, April 1, 2010 2:13 PM

Answers

  • Right, so if both my client and service side implement a workflow message exchange pattern using Send/Receive/SendReply/ReceiveReply I can have async service operation invocation. 

    However, as in my ICalculator example, if I'm trying to interact with a WCF service which implements the AsyncPattern I'm out of luck and would need to write a new WF Service that somehow wraps calling the existing WCF service operations in a Receive/SendReply workflow.

    It just seems like AsyncPattern = true is a common enough use case that it would benefit from a standard (shipped) workflow component to help with coding a service client.

    Thanks anyways!

    • Marked as answer by Shawn of T Monday, July 12, 2010 5:18 PM
    Monday, July 12, 2010 5:17 PM

All replies

  • If you Add Service Reference in a Workflow project from Visual Studio 2010 on the Asynchronous Calculator sample you will get 4 activities in the toolbox for the 4 operations, Add, Subtract, Multiply and Divide, and you can use these activities to invoke the methods of the calculator synchronously from the workflow with no other special handling or steps required.

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

    Friday, April 9, 2010 8:07 PM
  • The question was how to invoke ASYNCHronously.
    Tuesday, June 22, 2010 12:38 PM
  • Hi, can you explain a little bit more on "invoke asynchronously"? what kind of experience you want? With a send activity, you do send the request first, and then do some other activities, later on you execute ReceiveReply. It is not a synchronized call. However, it is slightly different with calling by code. Comparing calling a service asynchronously using code, workflow does not allow you hook asynchronous result event.

    thanks,

    Anders


    This posting is provided "AS IS" and confers no rights or warranties.
    Wednesday, June 23, 2010 3:35 PM
  • Right, so if both my client and service side implement a workflow message exchange pattern using Send/Receive/SendReply/ReceiveReply I can have async service operation invocation. 

    However, as in my ICalculator example, if I'm trying to interact with a WCF service which implements the AsyncPattern I'm out of luck and would need to write a new WF Service that somehow wraps calling the existing WCF service operations in a Receive/SendReply workflow.

    It just seems like AsyncPattern = true is a common enough use case that it would benefit from a standard (shipped) workflow component to help with coding a service client.

    Thanks anyways!

    • Marked as answer by Shawn of T Monday, July 12, 2010 5:18 PM
    Monday, July 12, 2010 5:17 PM