Freigeben über


State machine workflow web service example

Being able to have a StateMachineWorkflow hold state across multiple different web service calls can be very useful. This example will show you how to get start. The first step is to create your interface. For this example I will be using the following:

public interface IOrderService

{

    string CreateOrder(string id);

    string UpdateOrder(string id);

    string ProcessOrder(string id);

    void CancelOrder(string id);

    string ShipOrder(string id);

    string GetOrderStatus();

}

To implement one of the methods add a WebServiceInputActivity, which is an IEventActivity, into an EventDriven on the state machine workflow or any of the states contained within it. After setting the InterfaceType and the Method name the input parameters will appear in the property browser. Bind them to workflow level variables so that you can use them across the workflow. Add any activities needed to do the work for the method followed by a WebServiceOutputActivity. After setting the InputActivityName the out parameters for the method are displayed so that you can bind to the variables containing the results. After implementing all the methods you need right click on the project and choose Publish as Web Service to create the web service project.

In order to make multiple calls to the same web service you need to make sure that you have added a CookieContainer like below:

localhost.StateMachineWorkflow_WebService webservice = new localhost.StateMachineWorkflow_WebService();

webservice.CookieContainer = new CookieContainer();

After the host restarts If you want to send a web service method call to an already started instance you need the instance id for the workflow. Then you add it to the cookie container like the folowing:

webservice.CookieContainer.Add(new Cookie("WF_WorkflowInstanceId", instanceId, "/", "localhost"));

If you are using other items in the cookie container serializing / deserializing the entire container would contain the required workflow instance id and you would not need to use the suggestion above.

 

Before running the example below make sure you follow the steps in the readme.txt file.

StateMachineWebServiceExample.exe