The Problem SolverWIndows Workflow Foundation
HomeShow ChangesEditPrintRecent ChangesSubscriptionsLost and FoundFind ReferencesRename

Search

History

26-10-2009 09:57:5118-6-2009 10:46:4518-6-2009 03:44:4117-6-2009 21:21:449-6-2009 12:56:07

List all versions

Workflow Web Service
.

chireld

Summary

When we start a workflow instance through a web service we might need to call it a second time. No big deal, all we need to do is add a second WebServiceInputActivity with a matching WebServiceOutputActivity to the workflow and we are good to go. However when we try to call the second method from our client we get the following error:

Server was unable to process request.

Current session has no workflow instance associated with it.

Well that is because the workflow engine adds a cookie named WF_WorkflowInstanceId to the response used to connect the second call to the same workflow. Alright the solution is simple; add the following to the web service before the first call:

workflows.CookieContainer = New CookieContainer()

Now everything works like a charm.

But suppose this is a long running workflow and we need to communicate with the same workflow a day later. We can hardly keep the proxy and cookie container in memory all this time. Well again the trick is simple, just save the details from the cookie, the Name, value, path and the domain and uses these to recreate the cookie next day.

Example client code:

Imports System.Net
 
Module Module1
    Private _cookieName As String
    Private _cookieValue As String
    Private _cookiePath As String
    Private _cookieDomain As String
 
    Sub Main()
        SubmitExpenses()
 
        GetStatus()
        Console.ReadLine()
    EndSub
 
    ''' <summary>
    ''' Day one, submit the expenses.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SubmitExpenses()
        Dim workflows As New workflows.Workflow1_WebService
        workflows.CookieContainer = New CookieContainer()
 
        workflows.Submit("Holiday", 1000.0)
 
        ' Save the cookie info for next request
        Dim cookie As Cookie
        cookie = workflows.CookieContainer.GetCookies(New Uri(workflows.Url))(0)
        _cookieName = cookie.Name
        _cookiePath = cookie.Path
        _cookieValue = cookie.Value
        _cookieDomain = cookie.Domain
    EndSub
 
    ''' <summary>
    ''' Day two, come back and find its aproved :-)
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub GetStatus()
        Dim workflows As workflows.Workflow1_WebService
        workflows = New workflows.Workflow1_WebService
 
        workflows.CookieContainer = New CookieContainer()
        Dim cookie As New Cookie(_cookieName, _cookieValue, _cookiePath, _cookieDomain)
 
        workflows.CookieContainer.Add(cookie)
        Console.WriteLine(workflows.GetStatus())
    End Sub
End Module
Wiki Usage

This wiki site is supposed to be a shared resource. As a shared resource everyone is encouraged to add new content or modify existing content!

Enjoy the WF wiki.

Recent Topics