This one caused me quite a bit of grief this week – maybe I can save someone else some pain. When configuring content-based correlation in the Workflow (4.0/4.5) designer, I think there’s a subtle bug in the dialog that allows you to choose the correlation key and XPath expression used to establish correlation on a Receive or SendReply activity.
It manifests itself when the workflow engine attempts to apply the correlation query at runtime:
A correlation query yielded an empty result set. Please ensure correlation queries for the endpoint are correctly configured.
It only occurs under the following conditions:
- The message or parameter that contains the correlation is a complex DataContract (i.e. not a primitive value type).
- That DataContract type is derived from another base class DataContract.
- The correlation property comes from the base class.
- The base class DataContract and the derived class DataContract are in different namespaces.
Under these conditions, the Add Correlation Initializers dialog sets the namespace of the property as being defined in the namespace of the derived class, not the base class.
Fortunately the fix is easy – you can manually edit the XAML to refer to the namespace of the base class instead, e.g:
<XPathMessageQuery x:Key="key1"> <XPathMessageQuery.Namespaces> <ssx:XPathMessageContextMarkup> <x:String x:Key="xg0">http://schemas.datacontract.org/2004/07/ClassLibrary2</x:String> <x:String x:Key="xgSc">http://tempuri.org/</x:String> </ssx:XPathMessageContextMarkup> </XPathMessageQuery.Namespaces>sm:body()/xgSc:StartResponse/xgSc:StartResult/xg0:Id</XPathMessageQuery>