Answered Trouble with WebService and Persistence

  • Thursday, February 02, 2006 2:01 AM
     
     
    Hello all, I'm newer to the workflow world and I have a few questions :

    First, a little background:

    I've currently got a very simple sequential workflow wraped in WebServiceInput and WebServiceOutput and all interfaces and everything are setup correctly. 

    I use the publish as web service option and all is well.

    I then try to execute the web service using the "Invoke" button that is on the default web service form:  I then get this error:

    System.InvalidOperationException: The workflow hosting environment does not have a persistence service as required by an operation on the workflow instance "d385e441-41b7-46f9-a6d0-43478e685a0d".


    This is very confusing to me because I do not wanta persistence environment. I just want my workflow to run from start to finish when the method is called. Can I turn of persistence in the web.config? Is this a synchronous/asynchronous issue?

    Even stranger is that if I create a Host application form or console and add the web reference, I can use the proxy class to call my method as many times as I want, it performs *exactly* how I want it to, I guess maybe there is just something I am missing with the default web service form that is produced for you?


    Any help will be greatly appreciated!

    thanks,

    Kevin Booth

Answers

  • Friday, March 10, 2006 11:42 PM
     
     Answered

    Internally this is how it works.

    If Client(Browser/WebServiceClientProtocol derivative) makes request without cookies, WorkflowRuntime will check to see if that particular operation can activate an worklow instance(i.e if the operation is marked as activation in the workflow) if yes then a new instance will be created and the corresponding cookies will be sent back to client.

    If the client supports cookies(i.e Browser by default accepts cookies unless disabled explicitly, WebServiceClientProtocol class doesnt support cookie by default unless you populate "CookieContainer" Property) and makes subsequent request with that cookie, then server will always try to locate the worklow instance attached to it, if the workflow is not in memory(dehydrated/completed/terminated) it will query the persistence service for retrieval.

    If persistence service exist and the worklow instance is alive then it will be rehydrated and request will be serviced by it. If the workflow instance is already complted/terminated, and WorkflowInstanceException will be thrown by the persistenceservice(stating wotrkflow couldnot be found .blah blah..).

    If persistence service never existed and worklow instance is not available in memory, this is what you will get, basically it means runtime doesnt have instance in-memory and it doesnt know where to get it since there is no persistence service.

    So it works first time because new browser session - no cookie - activation request.

    Subsequent request with same browser window - cookie is cached by browser - your request contains routing cookie - following request, workflowruntime tries to find instance and fails:) since it is already completed.

     

     

     

All Replies

  • Thursday, February 02, 2006 3:22 PM
     
     

    Anyone have any ideas?

     

    thanks,

     

    Kevin

  • Saturday, February 04, 2006 2:04 AM
     
     

    Kevin,

    Are the WS-Input and Ws-Output the only activities on the workflow?  Also, do you always see the error when invoking the web service through the .asmx site, or does the error show up intermittently?

  • Wednesday, March 01, 2006 11:18 PM
     
     

    Probably the Guid ,shown in the errormessage is not he same as the Id the runtimeworkflow has. Therfore the workflow this it is a persisted workflow (it does NOT want to persist your new stuff, it thinks it's allready out there).

    Goed luck,

    Remco van Reij

  • Thursday, March 09, 2006 4:29 PM
     
     
    I have the same error every time I invoke the workflow the second time. In first invokation everything good. I have another activities between invoke - response sequence.
  • Thursday, March 09, 2006 4:55 PM
     
     

    Can you check if the web.config has the following line -

    <add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" UnloadOnIdle="true" ConnectionString="Initial Catalog=WorkflowStore;Data Source=.;Integrated Security=SSPI;" />

    Actually this is what happens - After every Webservice input/ouput pairs gets executed the state of the WF needs to get persisted.

    So I guess in your case there is no persistence service and hence the problem.

    Please also make sure to run the scripts that installs the database in your SQL server and assigns appropriate permissions.

    The scripts can be found here -

    C:\WINDOWS\WinFX\v3.0\Windows Workflow Foundation\SQL

    Thanks,

    Kushal.

  • Thursday, March 09, 2006 5:27 PM
     
     

    The problem occures only than trying to check the application throuth wep page form. I create a client to invoke the web service and averything working.

     

  • Thursday, March 09, 2006 5:31 PM
     
     

    Hi,

    I don't exactly understand why you are talking about sql server: I understand that the problem occurs also in simple workflow publishe d as web service with simple code exec activity inside. But the ideya you get is right - should be anythere configuration property to denya from WF environment unload activity after execution. Where this great place?

     

    Thanks,

    Vasya.

  • Thursday, March 09, 2006 5:51 PM
     
     

    Some of the activities require persistence service so if you have any of them in your workflow, you have to have a persistence service added to your config file.

    So, if any of the activities you use impement PersistOnCloseAttribute, you have to have Persistenceservice.

  • Thursday, March 09, 2006 7:06 PM
     
     

    Vasya -

        You say, the first invocation works fine but the subsequent ones fail. Does you workflow complete after every invocation?

     

    Here is my thought: You have cookies turned on and GUID is used for sessionId. On the first invocation a new workflow with GUID1(say) gets created by the ASP.Net and on returning results the workflow finishes too. Note the workflow is completed and not persisted to the database.

    On the second invocation, previous workflow GUID is sent and by correlation workflow runtime tries to find workflow with instance GUID1. However, there is no in memory copy of it, so it thinks the workflow might have persisted and looks for a persistence service.

     

    If you want to use cookies and correlate on multiple invocations to the same webservice you have to keep the workflow alive. One way to achieve this would be to have the first invocation be an IsActivating call, and group the rest of the expected calls in a EvenHandling scope keeping the main thread alive by checking for some condition until, say a specific call is received (closing request).

     

    Let me know if this makes sense...

     

    Thanks,

    Vignesh

  • Thursday, March 09, 2006 8:34 PM
     
     

    Thank you, Vignesh,

    all that you say make sence. Additionaly I have check that if I open another browser and try to invoke the workflow - it works one time and for second invokation also crashed.

     

    System.InvalidOperationException: The workflow hosting environment does not have a persistence service as required by an operation on the workflow instance &quot;78097c9b-b9c9-43b8-aef5-959729d295ae&quot;.
       at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor)
       at System.Workflow.Runtime.WorkflowRuntime.Load(Guid& key, CreationContext context)
       at System.Workflow.Runtime.WorkflowInstance.EnqueueItem(IComparable queueName, Object item, IPendingWork pendingWork, Object workItem)
       at System.Workflow.Activities.WorkflowWebService.SafeEnqueueItem(WorkflowInstance instance, EventQueueName key, MethodMessage message)
       at System.Workflow.Activities.WorkflowWebService.Invoke(Type interfaceType, String methodName, Boolean isActivation, Object[] parameters)
       at MyMainWorkflow.MyWorkflow_WebService.ReceiveAndProcessData(String sData) in C:\Documents and Settings\vasya\Local Settings\Temp\gslswpfn.cs:line 39

    As i already say i wrote client and it invoke my method withot problem.

     

    Thank you,

    Vasya.

  • Thursday, March 09, 2006 8:59 PM
     
     

    Vasya,

    Your workflow completes after first invokation. How many WebServiceInputs do you have in your workflow?

    It works in your client application because you are not adding a cookie container to your client. So your client always creates a new workflow instance.

    This is expected behaviour. When browser send a workflow instance ID from previous call cookie, WF runtime tries to locate that instance by ID. If workflow has complete in previous call, runtime does not find an instance and tries to load that ID from persistence serivice. Error message may be confusing, but this is expected behavior.

    Thanks,

  • Friday, March 10, 2006 11:42 PM
     
     Answered

    Internally this is how it works.

    If Client(Browser/WebServiceClientProtocol derivative) makes request without cookies, WorkflowRuntime will check to see if that particular operation can activate an worklow instance(i.e if the operation is marked as activation in the workflow) if yes then a new instance will be created and the corresponding cookies will be sent back to client.

    If the client supports cookies(i.e Browser by default accepts cookies unless disabled explicitly, WebServiceClientProtocol class doesnt support cookie by default unless you populate "CookieContainer" Property) and makes subsequent request with that cookie, then server will always try to locate the worklow instance attached to it, if the workflow is not in memory(dehydrated/completed/terminated) it will query the persistence service for retrieval.

    If persistence service exist and the worklow instance is alive then it will be rehydrated and request will be serviced by it. If the workflow instance is already complted/terminated, and WorkflowInstanceException will be thrown by the persistenceservice(stating wotrkflow couldnot be found .blah blah..).

    If persistence service never existed and worklow instance is not available in memory, this is what you will get, basically it means runtime doesnt have instance in-memory and it doesnt know where to get it since there is no persistence service.

    So it works first time because new browser session - no cookie - activation request.

    Subsequent request with same browser window - cookie is cached by browser - your request contains routing cookie - following request, workflowruntime tries to find instance and fails:) since it is already completed.

     

     

     

  • Wednesday, May 10, 2006 3:12 PM
     
     
    Thanks.

    Any chance to change this behaviour? If no persited instance or no persitence store found then start again as if no cookie is given?

    Martin

  • Tuesday, May 16, 2006 7:22 PM
     
     

    No, That will be technically wrong. User addressing request to specific instance(through cookie headers), if the instance is not available the right thing to do is to send exception rather than auto creating an instance either with same instance id or for the sake different instance id, user may not have intended that behavior.