Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Respondida WF4 Correlation issue

  • lunes, 16 de enero de 2012 17:57
     
     
    I am creating a workflow exposed as a WCF service. Everything works fine when I call this service, however if i call it multiple times (in a loop in my case) it doesn't work. The issue I'm having is that the last call in the loop is overwriting the parameters used in whatever call is currently running so i get errors in what i want to do. I have the contracts set up as oneway operations since i don't need to respond to the user through the ui (i email them a notification when everything is done). Also i have query initializers and correlation set up but it doesn't appear to be working, Any ideas? I also tried new-uping a controller every time i call the service but that has the same issue.

Todas las respuestas

  • lunes, 16 de enero de 2012 18:07
    Moderador
     
     

    Hi datg,
    I'm trying to understand the issue, but I'm not sure if I'm visualizing the shape of your workflow correctly. It sounds like you have multiple Receive activities. Probably inside a loop.

    You also mentioned correlation, and that the 'last call in the loop' is overwriting the parameters used.

    -What shape is your workflow, can you add code, or a picture to make things clearer?
    -Is the 'last call in the loop' referring to a receive activity?
    -How did you set up your correlations in more detail?
    -What exactly is the undesired overwriting behavior you are experiencing? What is being overwritten? When?

    Tim

  • lunes, 16 de enero de 2012 20:35
     
     

    There is only one receive activity, the mutltiple calls happen in my web app such as

     

    foreach(....)

    {

     new portalcontroller().copyportal(parameters1, .....);

    }

    the correlations i have set on the receive activity are a query correlation intializer using a passed in clientId, this will always be unique to the calls.

    i also have that receive to correlate on that handle for that same property.

  • martes, 17 de enero de 2012 0:38
    Moderador
     
     

    >the correlations i have set on the receive activity are a query correlation intializer using a passed in clientId, this will always be unique to the calls.

    From what you say here, it sounds like correlation should not actually happen at all in your test scenario.
    If so, what this means is that a fresh instance of the workflow will be activated for each call you make to the service, which could also explain why you see the received parameters in the workflow updated.

    So currently I'm wondering if the problem is, from your point of view that multiple instances of the workflow runs, or if it is that you have some unexpected leaking of data between workflow instances which are running simultaneously. If it is the latter leaking between issue, then I would guess it is probably going to be related to a custom activity which you have written that doesn't use InArgument<T>/Variable<T> for storing instance specific data, but just sets object properties or statics.

    Tim

  • martes, 17 de enero de 2012 14:08
     
     
    That is actually the behavior i want, i want each time i call the workflow a new instance to be created with a new set of data. Is there anyway to mirror the InstanceContextMode = InstanceContextMode.PerCall that we put on WCF services in WF4? The problem i am having is what you are saying " or if it is that you have some unexpected leaking of data between workflow instances which are running simultaneously " I have many custom activities but all of them are using inArguments, any ideas?
  • jueves, 19 de enero de 2012 22:54
    Moderador
     
     

    I'm still confused about one point, which is whether you think the problem is that a new instance is not getting created when you want it to, or whether existing new instances are malfuncitioning.

    But assuming it is the first problem, that instances are being reused when you actually want new instances, then the question I have for you is 'is there a reason you are using correlation?'.

    Correlation is what causes messages to go to an existing workflow instance rather than create a new instance. If you don't use correlation at all, the message will go to a new WF instance every time. Which should be exactly the same as InstanceContextMode = InstanceContextMode.PerCall.

    Tim


  • viernes, 27 de enero de 2012 14:39
     
     
    The issue I'm havingi would guess is that new instances are malfunctioning. I have taken all correlation related code out of the workflow but the same behavior is happening. It seems the first instance starts the workflow but the second, third, etc instances write over that data somehow.
  • miércoles, 15 de febrero de 2012 10:35
     
     

    Hi,

    We are experiencing the same problem: multiple calls to a WF4 service are re-using the same activity instance multiple times. We are not using correlation in any way.

    Any ideas?

    Holger

  • sábado, 25 de febrero de 2012 0:56
    Moderador
     
     
    I'm still not clear enough on what's happening from your descriptions, I think you might need to consider posting a repro project.
    Tim
  • lunes, 12 de marzo de 2012 19:31
     
     
    My scenario is this, i have a client web app that needs to call the workflow i have set up. The calls to this workflow are in a foreach loop since there could be multiple instances of the workflow needed. My problem is that the calls to the workflow seem to happen at the same time on a single instance therefore the data that got sent last overwrites some of the global variables needed in all of the code activities to process the data. This gives me various sql errors and eventual failure since it processes a little with the first request then the remaining processing is with the new data from a subsequent request. This of course makes my service fail since the data just changes halfway through the call. What i need to happen is that each call to my workflow kicks off a new instance of the workflow that can run independently with its own set of data for each of the calls to it. I was trying to use correlation because i figures if the messages couldn't be correlated that a new instance would be created. Does that help at all?
  • martes, 13 de marzo de 2012 17:13
    Moderador
     
     

    >What i need to happen is that each call to my workflow kicks off a new instance of the workflow that can run independently with its own set of data for each of the calls to it.

    >I was trying to use correlation because i figures if the messages couldn't be correlated that a new instance would be created.

    These bits taken together confuse me. The first bit sounds like you don't want correlation to happen. Instead you want a new workflow instance for every call.

    The second bit sounds like you think you do want correlation to happen, but I still couldn't work out why, and in fact it seems to make no sense at all to use correlation given that you have only one Receive in the workflow.

    Correlation is a feature designed to let you

    a) have multiple Receives in a single workflow,

    b) let both Receives pull data into a single workflow instance (instead of creating separate workflow instances).

    After all this, I suspect the solution to your problem is simply don't use correlation.

    Tim

  • martes, 13 de marzo de 2012 17:28
     
     
    Right i don't want to use correlation i have removed that from my workflow but the same behavior is happening. It seems i can't create new instances of my workflow on each call which is what i need. 
  • miércoles, 14 de marzo de 2012 5:06
    Moderador
     
     

    >My problem is that the calls to the workflow seem to happen at the same time on a single instance therefore the data that got sent last overwrites some of the global variables needed in all of the code activities to process the data.

    You mentioned global variables, are you talking about workflow variables here, or static variables in code, or something else?
    Tim

  • miércoles, 14 de marzo de 2012 13:51
     
     
    Sorry, yes i am talking about workflow variables. I have a few mappings/ base and target ids needed in various code activities in the main sequence to achieve their jobs. 
  • miércoles, 14 de marzo de 2012 21:30
    Moderador
     
     

    Unless you follow up with any other surprising information, to me it sounds like you're describing a scenario that just shouldn't happen, i.e. a bug. If you agree, I would suggest you file full repro information on http://connect.microsoft.com/wf where it will become an official product bug and brought to the attention of the product team.
    Tim

  • viernes, 05 de octubre de 2012 14:15
     
     
    Hi did you solve the issue? I'm experiencing the same problem you described.
  • viernes, 05 de octubre de 2012 17:19
     
     
    I did actually. What i ended up having to do was go into each of my activities and set the cache metadata so that each activity would have a copy of the data to work with for that instance. This allowed each activated activity to work on the correct data when an instance is created.
  • lunes, 08 de octubre de 2012 15:07
     
     

    Thanks, so if I understood well I have to write the following code for each activity and each argument right?

     protected override void CacheMetadata(CodeActivityMetadata metadata)
            {
    RuntimeArgument formatArgument = new RuntimeArgument("Input1", typeof(string), ArgumentDirection.In);
                metadata.Bind(this.Input1, Input1Argument);
                metadata.AddArgument(Input1Argument);
    //so on for each argument
    }

  • martes, 09 de octubre de 2012 0:17
    Moderador
     
     Respondida
    I did actually. What i ended up having to do was go into each of my activities and set the cache metadata so that each activity would have a copy of the data to work with for that instance. This allowed each activated activity to work on the correct data when an instance is created.

    Aha! So you are not using workflow Variable<T> and Argument<T> to encapsulate state which is particular to a single workflow instance, instead of a workflow definition.

    I'm afraid this was all a by design behavior. In WF3 activity clones are created fresh for every execution of activity. In WF4 activity definitions (object instances) are shared between multiple executions of the same workflow definition. Only Variable and Argument state is stored per-instance.

    Tim

    • Marcado como respuesta Tony Giardino martes, 02 de abril de 2013 19:51
    •