Sunday, September 7, 2014

Create QueryCorrelationInitializer dynamically

This post tells about how to create the QueryCorrelationInitializer dynamically.

Step 1. Create the Correlation Handle

Variable<CorrelationHandle> queryHandle = new Variable<CorrelationHandle>();

Step 2. Create the object of QueryCorrelationInitializer. 
QueryCorrelationIntializer has 2 properties which needs to be set.

QueryCorrelationInitializer queryInitializer = new QueryCorrelationInitializer
{
      CorrelationHandle = new InArgument<CorrelationHandle>(queryHandle),
      MessageQuerySet = CreateMessegeSet("Request")
};


Step 3. Create the MessageQuerySet
Assembly Name : Name of your namespace

In case if you are passing the parameter through your contract. In my case i have a Request Object in my contract which contains the Workflow Id of current instance .

public static MessageQuerySet CreateMessegeSet(string strObject)
{
     var x = new XPathMessageQuery();
     x.Namespaces.AddNamespace("xg0", "http://schemas.datacontract.org/2004/07/<Assembly Name>");
     x.Expression = "sm:body()/xg0:" + strObject + "/xg0:WorkflowId";
     var messageQuerySet = new MessageQuerySet();
     messageQuerySet.Add("Key1", x);
     return messageQuerySet;

}

No comments:

Post a Comment