Thursday, April 21, 2011

Tip: How to create a One-Way WCF WF service that persist to a SQL server?

Based on the research that i have done recently on the Workflow service using WCF, any call to a time-based workflow that has a delay activity will block the caller until the delay activity and subsequent activity is finished. That's to say, a web request is blocked until the entire workflow finish running, say for 1 minute if the delay activity is set to 1 minute. This is not the service behavior that I wanted, instead I want the service call to return immediatly after hitting the delay activity and the workflow is persisted to the database.

This how one can create a one-way WCF call to the Workflow Service:
1. Create a WCF Service Activity in Visual Studio
2. Remove the ReplyRequest Messaging activity.
3. Click on the ReceiveRequest activity, remove the item from CorrelationIntializers. This is not needed for one-way communication.
4. The end result will look something like this

5. At the client side reference the Workflow Service. Right click on the service reference and click Configure Service. Check the Generate asynchronous operations check box.

6. One can make use of the referenced service as follow:

7. Make sure to call to the GetDataAsync function and close the connection when done. The request will return immediately after the workflow hits the delay activity.
The IIS will resume whatever that is persisted in the database automatically when the time is right.