locked
Instance not found - correlation newbie? RRS feed

  • Question

  • Hello

    I am in the proces of learning wf4 and I have run into a problem  I can't figure out.
    The idea of my simple test app is the following:
    A client can connect to the service and first call Init on the service, the workflow will then generate a random integer to use as a session identifier (SessionId).
    The client can then procede to call the DoCount service operation. By calling DoCount a Workflow variable 'Count' will be increased by 1 and returned to the client. When 'Count' reaches ten, the workflow should terminate. E.g i should be able to have multiple count clients which counts independently.

    The basic layout of the application is organized in a flowchart in the following manner:

    1. Start
    2. Assign Count = 0
    3. Sequence 1
      • Receive
      • Assign - Generates the random SessionId integer
      • SendReplyToReceive - Returns the SessionId to client and initializes the correlation handle, 'mainHandle' using the Query correlation initializer with the following XPath query:sm:body()/xg0:int (generated by selecting Content :Int32 from the dropdown in query list)
    4. Sequence 2
      • Receive - takes in a int parameter 'sessionId', CorrelatesOn is being linked to this parameter.
      • Assign - increase 'Count' by 1
      • SendReplyToReceive - returns 'Count' to client
    5. Decision
      • Count = 10 goto end
      • Count != 10 goto Sequence2

    I have looked at the CorrelatedCalculator example, which is similar, but can't figure it out. Since I don't really know what I have done wrong I include most of the code in this post (sorry)

    The full error msg from the client:
    The execution of an InstancePersistenceCommand was interrupted because the instance key 'e89eda78-d47a-0bf7-2402-b363fd26e1af' was not associated to an instance. This can occur because the instance or key has been cleaned up, or because the key is invalid. The key may be invalid if the message it was generated from was sent at the wrong time or contained incorrect correlation data.


    The xaml code 

    <Activity mc:Ignorable="sap" x:Class="CountWorkflow.Service.CountToTenWorkflow" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:av="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 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="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" 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=mscorlib" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=System.Core" 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:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <sap:WorkflowViewStateService.ViewState>
        <scg:Dictionary x:TypeArguments="x:String, x:Object">
          <x:Boolean x:Key="ShouldExpandAll">False</x:Boolean>
          <x:Boolean x:Key="ShouldCollapseAll">False</x:Boolean>
        </scg:Dictionary>
      </sap:WorkflowViewStateService.ViewState>
      <Flowchart sad:XamlDebuggerXmlReader.FileName="c:\users\bbuddy\documents\visual studio 2010\Projects\Correlation\CountWorkflow.Service\CountToTenWorkflow.xaml" sap:VirtualizedContainerService.HintSize="776,944">
        <Flowchart.Variables>
          <Variable x:TypeArguments="x:Int32" Name="Count" />
          <Variable x:TypeArguments="x:Int32" Name="SessionId" />
          <Variable x:TypeArguments="p:CorrelationHandle" Name="mainHandle" />
        </Flowchart.Variables>
        <sap:WorkflowViewStateService.ViewState>
          <scg:Dictionary x:TypeArguments="x:String, x:Object">
            <x:Boolean x:Key="IsExpanded">False</x:Boolean>
            <av:Point x:Key="ShapeLocation">250,2.5</av:Point>
            <av:Size x:Key="ShapeSize">60,75</av:Size>
            <av:PointCollection x:Key="ConnectorLocation">280,77.5 280,107.5 300,107.5 300,271</av:PointCollection>
            <x:Double x:Key="Height">907.54</x:Double>
            <x:Double x:Key="Width">762.5</x:Double>
          </scg:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <Flowchart.StartNode>
          <FlowStep x:Name="__ReferenceID3">
            <sap:WorkflowViewStateService.ViewState>
              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                <av:Point x:Key="ShapeLocation">179,271</av:Point>
                <av:Size x:Key="ShapeSize">242,58</av:Size>
                <av:PointCollection x:Key="ConnectorLocation">300,329 300,359 300,364</av:PointCollection>
              </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
            <Assign sap:VirtualizedContainerService.HintSize="242,58">
              <Assign.To>
                <OutArgument x:TypeArguments="x:Int32">[Count]</OutArgument>
              </Assign.To>
              <Assign.Value>
                <InArgument x:TypeArguments="x:Int32">0</InArgument>
              </Assign.Value>
            </Assign>
            <FlowStep.Next>
              <FlowStep x:Name="__ReferenceID6">
                <sap:WorkflowViewStateService.ViewState>
                  <scg:Dictionary x:TypeArguments="x:String, x:Object">
                    <av:Point x:Key="ShapeLocation">200,364</av:Point>
                    <av:Size x:Key="ShapeSize">200,52</av:Size>
                    <av:PointCollection x:Key="ConnectorLocation">300,416 300,446 300,454</av:PointCollection>
                  </scg:Dictionary>
                </sap:WorkflowViewStateService.ViewState>
                <Sequence sap:VirtualizedContainerService.HintSize="200,52">
                  <sap:WorkflowViewStateService.ViewState>
                    <scg:Dictionary x:TypeArguments="x:String, x:Object">
                      <x:Boolean x:Key="IsExpanded">True</x:Boolean>
                    </scg:Dictionary>
                  </sap:WorkflowViewStateService.ViewState>
                  <p:Receive x:Name="__ReferenceID0" CanCreateInstance="True" sap:VirtualizedContainerService.HintSize="255,92" OperationName="Init" ServiceContractName="CountService">
                    <p:Receive.CorrelatesOn>
                      <p:MessageQuerySet />
                    </p:Receive.CorrelatesOn>
                    <x:Null />
                  </p:Receive>
                  <Assign sap:VirtualizedContainerService.HintSize="255,58">
                    <Assign.To>
                      <OutArgument x:TypeArguments="x:Int32">[SessionId]</OutArgument>
                    </Assign.To>
                    <Assign.Value>
                      <InArgument x:TypeArguments="x:Int32">[New Random().Next()]</InArgument>
                    </Assign.Value>
                  </Assign>
                  <WriteLine sap:VirtualizedContainerService.HintSize="255,62" Text="[&quot;New client! Has SessionId=&quot; &amp; SessionId]" />
                  <p:SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendReplyToReceive" sap:VirtualizedContainerService.HintSize="255,92">
                    <p:SendReply.CorrelationInitializers>
                      <p:QueryCorrelationInitializer CorrelationHandle="[mainHandle]">
                        <p:XPathMessageQuery x:Key="key1">
                          <p:XPathMessageQuery.Namespaces>
                            <ssx:XPathMessageContextMarkup>
                              <x:String x:Key="xg0">http://schemas.microsoft.com/2003/10/Serialization/</x:String>
                            </ssx:XPathMessageContextMarkup>
                          </p:XPathMessageQuery.Namespaces>sm:body()/xg0:int</p:XPathMessageQuery>
                      </p:QueryCorrelationInitializer>
                    </p:SendReply.CorrelationInitializers>
                    <p:SendMessageContent>
                      <InArgument x:TypeArguments="x:Int32">[SessionId]</InArgument>
                    </p:SendMessageContent>
                  </p:SendReply>
                </Sequence>
                <FlowStep.Next>
                  <FlowStep x:Name="__ReferenceID2">
                    <sap:WorkflowViewStateService.ViewState>
                      <scg:Dictionary x:TypeArguments="x:String, x:Object">
                        <av:Point x:Key="ShapeLocation">200,454</av:Point>
                        <av:Size x:Key="ShapeSize">200,52</av:Size>
                        <av:PointCollection x:Key="ConnectorLocation">300,506 300,536 290,536 290,542.5</av:PointCollection>
                      </scg:Dictionary>
                    </sap:WorkflowViewStateService.ViewState>
                    <Sequence sap:VirtualizedContainerService.HintSize="200,52">
                      <sap:WorkflowViewStateService.ViewState>
                        <scg:Dictionary x:TypeArguments="x:String, x:Object">
                          <x:Boolean x:Key="IsExpanded">True</x:Boolean>
                        </scg:Dictionary>
                      </sap:WorkflowViewStateService.ViewState>
                      <p:Receive x:Name="__ReferenceID1" CorrelatesWith="[mainHandle]" sap:VirtualizedContainerService.HintSize="255,92" OperationName="DoCount" ServiceContractName="CountService">
                        <p:Receive.CorrelatesOn>
                          <p:XPathMessageQuery x:Key="SessId">
                            <p:XPathMessageQuery.Namespaces>
                              <ssx:XPathMessageContextMarkup>
                                <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                              </ssx:XPathMessageContextMarkup>
                            </p:XPathMessageQuery.Namespaces>sm:body()/xgSc:DoCount/xgSc:sessionId</p:XPathMessageQuery>
                        </p:Receive.CorrelatesOn>
                        <p:ReceiveParametersContent>
                          <OutArgument x:TypeArguments="x:Int32" x:Key="sessionId" />
                        </p:ReceiveParametersContent>
                      </p:Receive>
                      <WriteLine sap:VirtualizedContainerService.HintSize="255,62" Text="[&quot;Client(&quot; &amp; SessionId &amp; &quot;) Counted&quot;]" />
                      <Assign sap:VirtualizedContainerService.HintSize="255,58">
                        <Assign.To>
                          <OutArgument x:TypeArguments="x:Int32">[Count]</OutArgument>
                        </Assign.To>
                        <Assign.Value>
                          <InArgument x:TypeArguments="x:Int32">[Count + 1]</InArgument>
                        </Assign.Value>
                      </Assign>
                      <p:SendReply Request="{x:Reference __ReferenceID1}" DisplayName="SendReplyToReceive" sap:VirtualizedContainerService.HintSize="255,92">
                        <p:SendMessageContent DeclaredMessageType="x:Int32">
                          <InArgument x:TypeArguments="x:Int32">[Count]</InArgument>
                        </p:SendMessageContent>
                      </p:SendReply>
                    </Sequence>
                    <FlowStep.Next>
                      <FlowDecision x:Name="__ReferenceID4" Condition="[Count = 10]" sap:VirtualizedContainerService.HintSize="60,75">
                        <sap:WorkflowViewStateService.ViewState>
                          <scg:Dictionary x:TypeArguments="x:String, x:Object">
                            <av:Point x:Key="ShapeLocation">260,542.5</av:Point>
                            <av:Size x:Key="ShapeSize">60,75</av:Size>
                            <av:PointCollection x:Key="FalseConnector">320,580 430,580 430,480 400,480</av:PointCollection>
                            <av:PointCollection x:Key="TrueConnector">260,580 230,580 230,619 290,619 290,649</av:PointCollection>
                          </scg:Dictionary>
                        </sap:WorkflowViewStateService.ViewState>
                        <FlowDecision.True>
                          <FlowStep x:Name="__ReferenceID5">
                            <sap:WorkflowViewStateService.ViewState>
                              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                                <av:Point x:Key="ShapeLocation">184.5,649</av:Point>
                                <av:Size x:Key="ShapeSize">211,62</av:Size>
                                <av:PointCollection x:Key="ConnectorLocation">160,499 160,471 280,471 280,591 160,591 160,561</av:PointCollection>
                              </scg:Dictionary>
                            </sap:WorkflowViewStateService.ViewState>
                            <WriteLine sap:VirtualizedContainerService.HintSize="211,62" Text="Counted to ten" />
                          </FlowStep>
                        </FlowDecision.True>
                        <FlowDecision.False>
                          <x:Reference>__ReferenceID2</x:Reference>
                        </FlowDecision.False>
                      </FlowDecision>
                    </FlowStep.Next>
                  </FlowStep>
                </FlowStep.Next>
              </FlowStep>
            </FlowStep.Next>
          </FlowStep>
        </Flowchart.StartNode>
        <x:Reference>__ReferenceID3</x:Reference>
        <x:Reference>__ReferenceID2</x:Reference>
        <x:Reference>__ReferenceID4</x:Reference>
        <x:Reference>__ReferenceID5</x:Reference>
        <x:Reference>__ReferenceID6</x:Reference>
      </Flowchart>
    </Activity>

     


    Client code:

    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    
    
    
    
    
    
    
            {
    
    
    
    
    
    
    
                using (CountServiceClient client = new CountServiceClient())
    
    
    
    
    
    
    
                {
    
    
    
    
    
    
    
                    client.Open();
    
    
    
    
    
    
    
                    _sessionId = client.Init();
    
    
    
    
    
    
    
                    string text = "Client got SessionId=" + _sessionId;
    
    
    
    
    
    
    
                    AppendText(text);
    
    
    
    
    
    
    
                }
    
    
    
    
    
    
    
            }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
            private void button1_Click(object sender, RoutedEventArgs e)
    
    
    
    
    
    
    
            {
    
    
    
    
    
    
    
                using (CountServiceClient client = new CountServiceClient())
    
    
    
    
    
    
    
                {
    
    
    
    
    
    
    
                    client.Open();
    
    
    
    
    
    
    
                    DoCount request = new DoCount
    
    
    
    
    
    
    
                    {
    
    
    
    
    
    
    
                        sessionId = (int)_sessionId
    
    
    
    
    
    
    
                    };
    
    
    
    
    
    
    
                    int? number = client.DoCount(request);
    
    
    
    
    
    
    
                    AppendText(number.ToString());
    
    
    
    
    
    
    
                }
    
    
    
    
    
    
    
            }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
            void AppendText(string text)
    
    
    
    
    
    
    
            {
    
    
    
    
    
    
    
                textBox1.Text += text + "\n";
    
    
    
    
    
    
    
            }
    
    
    
    
    
    
    
    

     

    • Edited by BBuddy Thursday, November 12, 2009 2:41 PM xml highlight
    Thursday, November 12, 2009 2:30 PM

Answers

  • Hi there.
    The problem is with the XPath Query key values you have set inside your initializers.
    In your Init function you use the key name 'Key1'.  Then down in your DoCount function you used the key name 'SessID' in your CorrelatesOn property.
    The runtime needs to be able to look up the correct correlation key and it does that via the keyname.
    Once you set them the be the same key name, it should work.

    Hope that helps.
    Scott
    MS Developer Support
    • Marked as answer by BBuddy Friday, November 13, 2009 7:40 AM
    Friday, November 13, 2009 12:12 AM

All replies

  • Hi there.
    The problem is with the XPath Query key values you have set inside your initializers.
    In your Init function you use the key name 'Key1'.  Then down in your DoCount function you used the key name 'SessID' in your CorrelatesOn property.
    The runtime needs to be able to look up the correct correlation key and it does that via the keyname.
    Once you set them the be the same key name, it should work.

    Hope that helps.
    Scott
    MS Developer Support
    • Marked as answer by BBuddy Friday, November 13, 2009 7:40 AM
    Friday, November 13, 2009 12:12 AM
  • Thanks a bunch Scott.
    Guess i thought that key was a sort of internal label to that dialog to differentiate the different queries for yourself.
    (y)
    Friday, November 13, 2009 7:41 AM