locked
Content Correlation RRS feed

  • Question

  • I've Two RECEIVE activities correlates on say, EmployeeID. RECEIVE 1 takes Employee object as input. If the first receive which initializes the Query correlation initializer is called multiple times from the clients passing the same Employee object (example, employee id as 1), there will be as much instances will be created. Now, if a client calls the second RECEIVE method (which updates some of the properties of the employee object) by passing the employee Id as 1, will all the instances be updated?

    Friday, February 5, 2010 5:27 AM

All replies

  • Hi Kbskaran,

    According to my understanding, if the first receive initializes the handler on employee id, and you pass the same employee id to the first receive multiple times, only one instance will be created and the subsequence call will fail.

    Say there's a receive R1(employeeid) and you call R1(1) the first time, an instance will be created and a handle on employee with value 1 is created. When you call R1(1) for the second time, assuming the previous workflow is not completed yet, since there's already a handle that indicates an instance on the employeeid 1 is already started, the second call should fail.

    Thanks,
    Tony
    Friday, February 5, 2010 7:16 AM
  • Hi Tony, the second R1(1) is not failing if I've multiple correlation between multiple receives. Here is my xaml.

    <Activity mc:Ignorable="sap" x:Class="WorkflowConsoleApplication1.Workflow1" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:local="clr-namespace:WorkflowConsoleApplication1" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:p="clr-namespace:PatientModel;assembly=PatientModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:p2="clr-namespace:PatientModel;assembly=PatientModel" xmlns:p3="http://tempuri.org/" xmlns:s="clr-namespace:System;assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" xmlns:s1="clr-namespace:System;assembly=mscorlib" xmlns:s2="clr-namespace:System;assembly=System" xmlns:s3="clr-namespace:System;assembly=System.Xml" xmlns:s4="clr-namespace:System;assembly=System.Core" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sd1="clr-namespace:System.Data;assembly=System.Data.DataSetExtensions" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:ssa="clr-namespace:System.ServiceModel.Activities;assembly=System.ServiceModel.Activities" xmlns:ssx="clr-namespace:System.ServiceModel.XamlIntegration;assembly=System.ServiceModel" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:w="clr-namespace:WorkflowConsoleApplication1;assembly=WorkflowConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Sequence sad:XamlDebuggerXmlReader.FileName="D:\Bhaskar\WFTest\Correlation\PatientTest\WorkflowConsoleApplication1\Workflow1.xaml" sap:VirtualizedContainerService.HintSize="1047,1342">
        <Sequence.Variables>
          <Variable x:TypeArguments="p2:Patient" Name="currPatient" />
          <Variable x:TypeArguments="p1:CorrelationHandle" Name="__handle1" />
          <Variable x:TypeArguments="p1:CorrelationHandle" Name="__handle2" />
          <Variable x:TypeArguments="local:AddInstances" Name="patientColl" />
        </Sequence.Variables>
        <sap:WorkflowViewStateService.ViewState>
          <scg3:Dictionary x:TypeArguments="x:String, x:Object">
            <x:Boolean x:Key="IsExpanded">True</x:Boolean>
          </scg3:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <Sequence sap:VirtualizedContainerService.HintSize="1025,697">
          <Sequence.Variables>
            <Variable x:TypeArguments="x:Int32" Name="insCount" />
            <Variable x:TypeArguments="local:AddInstances" Name="addInstance" />
          </Sequence.Variables>
          <sap:WorkflowViewStateService.ViewState>
            <scg3:Dictionary x:TypeArguments="x:String, x:Object">
              <x:Boolean x:Key="IsExpanded">True</x:Boolean>
            </scg3:Dictionary>
          </sap:WorkflowViewStateService.ViewState>
          <p1:Receive x:Name="__ReferenceID0" CanCreateInstance="True" sap:VirtualizedContainerService.HintSize="255,86" OperationName="AddPatient" ServiceContractName="IService">
            <p1:Receive.CorrelatesOn>
              <p1:MessageQuerySet />
            </p1:Receive.CorrelatesOn>
            <p1:Receive.CorrelationInitializers>
              <p1:QueryCorrelationInitializer CorrelationHandle="[__handle2]">
                <p1:XPathMessageQuery x:Key="key1">
                  <p1:XPathMessageQuery.Namespaces>
                    <ssx:XPathMessageContextMarkup>
                      <x:String x:Key="xg0">http://schemas.datacontract.org/2004/07/PatientModel</x:String>
                      <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                    </ssx:XPathMessageContextMarkup>
                  </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:AddPatient/xgSc:inPatient/xg0:Diagnosis</p1:XPathMessageQuery>
                <p1:XPathMessageQuery x:Key="key2">
                  <p1:XPathMessageQuery.Namespaces>
                    <ssx:XPathMessageContextMarkup>
                      <x:String x:Key="xg0">http://schemas.datacontract.org/2004/07/PatientModel</x:String>
                      <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                    </ssx:XPathMessageContextMarkup>
                  </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:AddPatient/xgSc:inPatient/xg0:PatientID</p1:XPathMessageQuery>
              </p1:QueryCorrelationInitializer>
              <p1:QueryCorrelationInitializer CorrelationHandle="[__handle1]">
                <p1:XPathMessageQuery x:Key="key1">
                  <p1:XPathMessageQuery.Namespaces>
                    <ssx:XPathMessageContextMarkup>
                      <x:String x:Key="xg0">http://schemas.datacontract.org/2004/07/PatientModel</x:String>
                      <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                    </ssx:XPathMessageContextMarkup>
                  </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:AddPatient/xgSc:inPatient/xg0:Initial</p1:XPathMessageQuery>
              </p1:QueryCorrelationInitializer>
            </p1:Receive.CorrelationInitializers>
            <p1:ReceiveParametersContent>
              <OutArgument x:TypeArguments="p2:Patient" x:Key="inPatient">[currPatient]</OutArgument>
            </p1:ReceiveParametersContent>
          </p1:Receive>
          <p1:SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendReplyToReceive" sap:VirtualizedContainerService.HintSize="255,86">
            <p1:SendParametersContent>
              <InArgument x:TypeArguments="x:String" x:Key="AddResult">Patient Created</InArgument>
            </p1:SendParametersContent>
          </p1:SendReply>
          <Assign sap:VirtualizedContainerService.HintSize="255,57">
            <Assign.To>
              <OutArgument x:TypeArguments="local:AddInstances">[addInstance]</OutArgument>
            </Assign.To>
            <Assign.Value>
              <InArgument x:TypeArguments="local:AddInstances">[AddInstances.Instance]</InArgument>
            </Assign.Value>
          </Assign>
          <InvokeMethod sap:VirtualizedContainerService.HintSize="255,125" MethodName="insCount">
            <InvokeMethod.TargetObject>
              <InArgument x:TypeArguments="local:AddInstances">[addInstance]</InArgument>
            </InvokeMethod.TargetObject>
            <InArgument x:TypeArguments="p2:Patient">[currPatient]</InArgument>
          </InvokeMethod>
          <WriteLine sap:VirtualizedContainerService.HintSize="255,59" Text="[&quot;Name : &quot; + currPatient.PatientName + &quot; ID : &quot; + currPatient.PatientID.ToString() + &quot; DOA : &quot; + currPatient.DOA.ToLongTimeString() + &quot; Initial : &quot; + currPatient.Initial + &quot; Diag: &quot; + currPatient.Diagnosis]" />
        </Sequence>
        <Parallel sap:VirtualizedContainerService.HintSize="1025,481">
          <Sequence sap:VirtualizedContainerService.HintSize="277,435">
            <sap:WorkflowViewStateService.ViewState>
              <scg3:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg3:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
            <p1:Receive x:Name="__ReferenceID1" CorrelatesWith="[__handle1]" sap:VirtualizedContainerService.HintSize="255,86" OperationName="UpdateDiag" ServiceContractName="IService">
              <p1:Receive.CorrelatesOn>
                <p1:XPathMessageQuery x:Key="key1">
                  <p1:XPathMessageQuery.Namespaces>
                    <ssx:XPathMessageContextMarkup>
                      <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                    </ssx:XPathMessageContextMarkup>
                  </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:UpdateDiag/xgSc:pInitial</p1:XPathMessageQuery>
              </p1:Receive.CorrelatesOn>
              <p1:ReceiveParametersContent>
                <OutArgument x:TypeArguments="x:String" x:Key="pInitial" />
              </p1:ReceiveParametersContent>
            </p1:Receive>
            <p1:SendReply Request="{x:Reference __ReferenceID1}" DisplayName="SendReplyToReceive" sap:VirtualizedContainerService.HintSize="255,86">
              <p1:SendParametersContent>
                <InArgument x:TypeArguments="x:String" x:Key="UpdateDiagResult">["Current Diagnosis: " + currPatient.Diagnosis]</InArgument>
              </p1:SendParametersContent>
            </p1:SendReply>
            <WriteLine sap:VirtualizedContainerService.HintSize="255,59" Text="[&quot;Seq2:&quot; + &quot;Name : &quot; + currPatient.PatientName + &quot; ID : &quot; + currPatient.PatientID.ToString() + &quot; DOA : &quot; + currPatient.DOA.ToLongTimeString() + &quot; Initial : &quot; + currPatient.Initial + &quot; Diag: &quot; + currPatient.Diagnosis]" />
          </Sequence>
          <Sequence sap:VirtualizedContainerService.HintSize="277,435">
            <sap:WorkflowViewStateService.ViewState>
              <scg3:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg3:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
            <p1:Receive x:Name="__ReferenceID2" CorrelatesWith="[__handle2]" sap:VirtualizedContainerService.HintSize="255,86" OperationName="UpdateMedi" ServiceContractName="IService">
              <p1:Receive.CorrelatesOn>
                <p1:XPathMessageQuery x:Key="key2">
                  <p1:XPathMessageQuery.Namespaces>
                    <ssx:XPathMessageContextMarkup>
                      <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                    </ssx:XPathMessageContextMarkup>
                  </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:UpdateMedi/xgSc:pID</p1:XPathMessageQuery>
                <p1:XPathMessageQuery x:Key="key1">
                  <p1:XPathMessageQuery.Namespaces>
                    <ssx:XPathMessageContextMarkup>
                      <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                    </ssx:XPathMessageContextMarkup>
                  </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:UpdateMedi/xgSc:diag</p1:XPathMessageQuery>
              </p1:Receive.CorrelatesOn>
              <p1:ReceiveParametersContent>
                <OutArgument x:TypeArguments="x:Int32" x:Key="pID" />
                <OutArgument x:TypeArguments="x:String" x:Key="diag" />
                <OutArgument x:TypeArguments="x:String" x:Key="medication">[currPatient.Medication]</OutArgument>
              </p1:ReceiveParametersContent>
            </p1:Receive>
            <p1:SendReply Request="{x:Reference __ReferenceID2}" DisplayName="SendReplyToReceive" sap:VirtualizedContainerService.HintSize="255,86">
              <p1:SendParametersContent>
                <InArgument x:TypeArguments="x:String" x:Key="UpdateMediResult">Medication Updated</InArgument>
              </p1:SendParametersContent>
            </p1:SendReply>
            <WriteLine sap:VirtualizedContainerService.HintSize="255,59" Text="[&quot;Medication &quot; + currPatient.Medication + &quot; Update to patient &quot; + currPatient.PatientName + &quot; ID: &quot; + currPatient.PatientID.ToString() + &quot; For Diag &quot; + currPatient.Diagnosis]" />
          </Sequence>
          <Sequence sap:VirtualizedContainerService.HintSize="277,435">
            <Sequence.Variables>
              <Variable x:TypeArguments="p1:CorrelationHandle" Name="__handle3" />
            </Sequence.Variables>
            <sap:WorkflowViewStateService.ViewState>
              <scg3:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg3:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
            <p1:Receive x:Name="__ReferenceID3" CorrelatesWith="[__handle2]" sap:VirtualizedContainerService.HintSize="255,86" OperationName="GetDOA" ServiceContractName="p3:IService">
              <p1:Receive.CorrelatesOn>
                <p1:XPathMessageQuery x:Key="key2">
                  <p1:XPathMessageQuery.Namespaces>
                    <ssx:XPathMessageContextMarkup>
                      <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                    </ssx:XPathMessageContextMarkup>
                  </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:GetDOA/xgSc:pID</p1:XPathMessageQuery>
                <p1:XPathMessageQuery x:Key="key1">
                  <p1:XPathMessageQuery.Namespaces>
                    <ssx:XPathMessageContextMarkup>
                      <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                    </ssx:XPathMessageContextMarkup>
                  </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:GetDOA/xgSc:Diag</p1:XPathMessageQuery>
              </p1:Receive.CorrelatesOn>
              <p1:Receive.CorrelationInitializers>
                <p1:RequestReplyCorrelationInitializer CorrelationHandle="[__handle3]" />
              </p1:Receive.CorrelationInitializers>
              <p1:ReceiveParametersContent>
                <OutArgument x:TypeArguments="x:Int32" x:Key="pID" />
                <OutArgument x:TypeArguments="x:String" x:Key="Diag" />
              </p1:ReceiveParametersContent>
            </p1:Receive>
            <p1:SendReply Request="{x:Reference __ReferenceID3}" DisplayName="SendReplyToReceive" sap:VirtualizedContainerService.HintSize="255,86">
              <p1:SendParametersContent>
                <InArgument x:TypeArguments="x:String" x:Key="result">[currPatient.DOA.ToLongTimeString()]</InArgument>
              </p1:SendParametersContent>
            </p1:SendReply>
          </Sequence>
        </Parallel>
      </Sequence>
    </Activity>
    Monday, February 8, 2010 6:09 AM
  • Hi Bhaskaran,

    The second call will fail on correlation because the key you provided can match to multiple instances, this is not allowed. Check MSDN page at:
    http://msdn.microsoft.com/en-us/library/ee358755(VS.100).aspx

    which has statement as following:

    The data that is used to identify the instance is hashed into a correlation key. Care must be taken to ensure that the data used for correlation is unique or else collisions in the hashed key could occur and cause messages to be misrouted. For example, a correlation based solely on a customer name may cause a collision because there may be multiple customers with the same name. The colon (:) should not be used as part of the data used to correlate the message because it is already used to delimit the message query’s key and value to form the string that is subsequently hashed.

    In your case, it's not a valid correlation if you first correlate on e.g. EmployeeID + Title, and latter correlate on EmployeeID only. You can consider using ContextCorrelation if there isn't a property that can identify instance.

    thanks,
    Anders

    This posting is provided "AS IS" and confers no rights or warranties.
    Tuesday, February 9, 2010 8:48 AM
  • Hi Bhaskaran,

    Are you using an instance store or not? If you are not using an instance store, you probably met a bug. I've reported the bug to the dev team and it is being worked on.

    Thanks,
    Tony
    Thursday, February 11, 2010 1:59 PM
  • Yes Tony. You are correct. I was not persisting the instance which allowed workflow to success on multiple R1(1)

    That was why I got confused and raised this.

    Thanks
    Bhaskaran

    Friday, February 12, 2010 11:42 AM