Connecting back up to a long running Workflow through a web service

Posted Friday, October 06, 2006 5:11 PM by Maurice
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 AsString
    Private _cookieValue AsString
    Private _cookiePath AsString
    Private _cookieDomain AsString
 
    Sub Main()
        SubmitExpenses()
 
        GetStatus()
        Console.ReadLine()
    EndSub
 
    ''' <summary>
    ''' Day one, submit the expenses.
    ''' </summary>
    ''' <remarks></remarks>
    PrivateSub SubmitExpenses()
        Dim workflows AsNew 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>
    PrivateSub GetStatus()
        Dim workflows As workflows.Workflow1_WebService
        workflows = New workflows.Workflow1_WebService
 
        workflows.CookieContainer = New CookieContainer()
        Dim cookie AsNew Cookie(_cookieName, _cookieValue, _cookiePath, _cookieDomain)
 
        workflows.CookieContainer.Add(cookie)
        Console.WriteLine(workflows.GetStatus())
    EndSub
 
EndModule
 
Enjoy!
Maurice de Beijer
 
Filed under: , ,

Comments

# re: Connecting back up to a long running Workflow through a web service

Saturday, April 28, 2007 11:42 PM by gaixiaojie

i have get help from this article,thank you!

# Workflow Publish as Web Service and Visual Studion 2008

Monday, April 28, 2008 8:50 AM by The Problem Solver

I am unsure if this is a problem with my PC but when I am building a workflow using the WebServiceInputActivity

# Workflow Publish as Web Service and Visual Studion 2008

Monday, April 28, 2008 9:32 AM by WF Community Bloggers

I am unsure if this is a problem with my PC but when I am building a workflow using the WebServiceInputActivity

Leave a Comment

(required) 
(required) 
(optional)
(required)