Correct way to create a State Machine

Hi

I am trying to create a statefull booking service (state machine workflow exposed as webservice). It has the following states. Created, TicketSelected, Pay, Comfirmed. My question is twofold.

First:

The Created state is the Initial state and has an eventdriven activity that waits for a webserivce call to arrive. When this comes i need to do some actions and the wait for a new webservice call (SelectTicket) so I can go to the "TicketSelected" state. My question is. Where should i wait for this "SelectTicket" webservice call? In the "Created" state? og should i create a new state called "WaitForTicketSelect" ?

I guess my problem is that my Created state would have to listen for two web service calls, if i do not have the "WaitForTicketSelect". Of these two WS calls CreateTicket would have to come first (marked as IsActivating) but it doesnt seem "clean" to have these two webservice inputs..or does it?

Second:

Lets we now are in the "TicketSelected" state. How do i insure that this particluar Booking is "corrolated" so i can have multiple instances running? Would i have to send the workflow instance id with all the webservice call as parameter or is there some build-in webservice correlations functionality?

Thanks in regards if you take your time to read and come with inpout to the above.

Regards

Anders K.J

[1462 byte] By [anderskj1] at [2007-12-25]
# 1

Anders

For #1, you can model two different events on the Created state, one for your initial call, and one for the event that should transition to the ticket selected state. Or, you could do as you say and add another state that goes between those two. Either way will work. In the first case, your activating sequence can just use SetState to go back to the Created state to wait for the second event.

For #2, there is a need to pass the worklfow instance id each time an event or web service input is sent. if you are using the Publish as Web Service functionality, or the equivalent manual process, the code is already in place to manage the id via cookies. This means your client code must support cookies for web services and correctly send back any cookies sent to it. Use the CookieContainer in .NET client code to do this.

You can also implement your own mechanism for instance correlation if you need to use something other than cookies.

Matt

MattMilner-Pluralsight at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2

Thanks for your input.

I am a little lost when it comes to WF as WebServices. I have my my StateMachine workflow project. I have choosen "Publish as WebService" and this seems to work fine with state.

Now lets say i need to corrolate this manually (i need to call the Web Service from a WinForm GUI). I need to corrolate the Workflow Instances based on eg. the Workflow Instace ID which i return to the GUI in the CreateBooking WebSerivice call.

Now where do I do this "manual" corelation? I could always send the instance ID with every web service call, but where should i intercept this call and make sure that the web serivice call is delegated to the correct worfklow instance (based on the workflow ID I eg, send as the first parameter?)

Thanks in regards.

Anders

anderskj1 at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 3

Sorry for the delay in responding, my alerts are not working correctly.

If you are doing the manual correlation yourself, one simple solution is the following:

1. Add a soap header to your web service requests and pass the instance ID in this header.

2. On the server side add an HTTP module or soap extension that pulls out the soap header and then writes the instance id into the __WorkflowInstanceID__ item on the HttpContext. (Make sure you remove the default http module from the web.config).

The default implementation, when using Publish as Web Service wizard, uses cookies to manage the instance id. If you want to leverage this you can use a cookie container in your client side code. Simply having the cookie container works if you are only interacting with one web service and one instance. However, if you are interacting with several instances, you'll need to set the cookie correctly in your client side code each time your want to access the service for a given workflow instance.

Matt

MattMilner-Pluralsight at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 4

This approach works for webserviceinput activities using different methods in a workflow. My question is how to correlation activities using the same web method.

For example, I have a workflow to management human interaction. The workflow invokes another web service twice to create two human tasks. It gets two task IDs from the web service. Then it's waiting for the response separately. The two webserviceinput activities use the same interface and method. I am hoping that the task ID (or combined with workflow instance ID) could serve as the correlation ID to the right activity. I understand that the cookie could make it to route to the right workflow instance. But how to route to the correct activity?

I know that BPEL4WS can route to the correct activity if task ID is global unique.

samltd at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 5

Correction.

BPEL4WS does not specify the behaviour if there are two receiving activities waiting on the same partner link + port + method.

samltd at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 6

With the state machine and web service, you would model the event, and use the same event driven for both responses. You would need to manage updating state correctly using the task id. when you receive the first response, you would transition back to the same state and wait for the second response (use an if/else in the event driven) and then after you get the second response transition to your next state.

Matt

MattMilner-Pluralsight at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified