How to traverse RDF tree in SPARQL and find connections outside of the tree? - sparql

Considering a tree with the root node "A" and "hasChild" relationships (e.g. product structure) as following:
Target is to find out:
What nodes have parents outside of the tree?
In this case the answer should be ‘B’ and ‘Q’ as they have parents outside of the tree.
The query should go to every node and check its parents rather than creating a list of children and the check every one of them I guess.
How can I efficiently (should work for millions of nodes) traverse this tree an SPARQL and answer this?
This is what i tried but gave 0 results:
PREFIX xxx: <http://example.org/xxx#>
select * where {
xxx:A xxx:hasChild* ?child .
?child ^xxx:hasChild ?foreignParent .
?child ^xxx:hasChild ?parent .
FILTER (?parent =! ?foreignParent) .
}
Attached the respective sample data:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xxx="http://example.org/xxx#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xml:base="http://example.org/xxx">
<owl:Ontology rdf:about="">
<owl:versionInfo>Created with TopBraid Composer</owl:versionInfo>
</owl:Ontology>
<owl:Class rdf:ID="Other">
<rdfs:label>Other</rdfs:label>
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
</owl:Class>
<owl:Class rdf:ID="Item">
<rdfs:label>Item</rdfs:label>
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
</owl:Class>
<rdf:Property rdf:ID="hasChild">
<rdfs:range rdf:resource="#Item"/>
<rdfs:range rdf:resource="#Other"/>
<rdfs:domain rdf:resource="#Item"/>
<rdfs:label>has child</rdfs:label>
</rdf:Property>
<xxx:Other rdf:ID="Fake_1">
<xxx:hasChild>
<xxx:Item rdf:ID="B">
<xxx:hasChild>
<xxx:Item rdf:ID="D">
<xxx:hasChild>
<xxx:Item rdf:ID="F"/>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="E"/>
</xxx:hasChild>
</xxx:Item>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="C"/>
</xxx:hasChild>
</xxx:Item>
</xxx:hasChild>
<rdfs:label>Fake 1</rdfs:label>
</xxx:Other>
<xxx:Other rdf:ID="Fake_2">
<xxx:hasChild>
<xxx:Item rdf:ID="Q"/>
</xxx:hasChild>
<rdfs:label>Fake 2</rdfs:label>
</xxx:Other>
<xxx:Item rdf:ID="A">
<xxx:hasChild>
<xxx:Item rdf:ID="G">
<xxx:hasChild>
<xxx:Item rdf:ID="X">
<xxx:hasChild>
<xxx:Item rdf:ID="Z"/>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="Y"/>
</xxx:hasChild>
</xxx:Item>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="R">
<xxx:hasChild>
<xxx:Item rdf:ID="W"/>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="S">
<xxx:hasChild>
<xxx:Item rdf:ID="V"/>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="U"/>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="T"/>
</xxx:hasChild>
</xxx:Item>
</xxx:hasChild>
</xxx:Item>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="M">
<xxx:hasChild rdf:resource="#Q"/>
<xxx:hasChild>
<xxx:Item rdf:ID="P"/>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="O"/>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="N"/>
</xxx:hasChild>
</xxx:Item>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="H">
<xxx:hasChild>
<xxx:Item rdf:ID="L"/>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="K"/>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="J"/>
</xxx:hasChild>
<xxx:hasChild>
<xxx:Item rdf:ID="I"/>
</xxx:hasChild>
</xxx:Item>
</xxx:hasChild>
</xxx:Item>
</xxx:hasChild>
<xxx:hasChild rdf:resource="#B"/>
</xxx:Item>
</rdf:RDF>

The trick is to make sure there is no path from your tree root to your foreign parent node. You can do that by means of a FILTER NOT EXISTS construction, like so:
PREFIX xxx: <http://example.org/xxx#>
SELECT ?child ?foreignParent
WHERE {
xxx:A xxx:hasChild+ ?child.
?child ^xxx:hasChild ?foreignParent.
FILTER NOT EXISTS { xxx:A xxx:hasChild* ?foreignParent }
}
Whether this scales to "millions of nodes" will depend on a) the depth of the tree and b) the triplestore you use. I ran the query using RDF4J on my laptop with the test data you provided, and got this:
Evaluating SPARQL query...
+-------------------------------------+-------------------------------------+
| child | foreignParent |
+-------------------------------------+-------------------------------------+
| <http://example.org/xxx#B> | <http://example.org/xxx#Fake_1> |
| <http://example.org/xxx#Q> | <http://example.org/xxx#Fake_2> |
+-------------------------------------+-------------------------------------+
2 result(s) (19 ms)

Related

Select single ontology class and all of its axioms and annotations as a subset

Is there a SPARQL or other method to extract a single class and all of its associated axioms and annotations from an ontology? For example, assume one had a list of classes from one ontology that they wanted to add to another ontology.
For example, consider the following class from IDO: http://purl.obolibrary.org/obo/IDO_0000406 (see below). In this example, it might be easier to simply parse the contents of the ontology's OWL file using a regex pattern such as /(<owl:Class .+?\s\s\s\s\s\n<\/owl:Class>/ to capture all of the details of every class after which the classes of interest could simply be filtered out and appended to a new OWL file.
<owl:Class rdf:about="http://purl.obolibrary.org/obo/IDO_...">
...
</owl:Class>
...
<owl:Class rdf:about="http://purl.obolibrary.org/obo/IDO_0000406">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/IDO_0000452"/>
<rdfs:subClassOf>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<owl:Restriction>
<owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0000052"/>
<owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/OBI_0100026"/>
</owl:Restriction>
<owl:Restriction>
<owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000054"/>
<owl:allValuesFrom>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://purl.obolibrary.org/obo/BFO_0000015"/>
<owl:Restriction>
<owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/>
<owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/IDO_0000625"/>
</owl:Restriction>
<owl:Restriction>
<owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/>
<owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/TRANS_0000000"/>
</owl:Restriction>
<owl:Restriction>
<owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/>
<owl:someValuesFrom>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://purl.obolibrary.org/obo/IDO_0000626"/>
<owl:Class>
<owl:complementOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000066"/>
<owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/IDO_0000457"/>
</owl:Restriction>
</owl:complementOf>
</owl:Class>
</owl:intersectionOf>
</owl:Class>
</owl:someValuesFrom>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</rdfs:subClassOf>
<obo:IAO_0000115 xml:lang="en">An infectious disposition to become part of a disorder only in organisms whose defenses are compromised.</obo:IAO_0000115>
<obo:IAO_0000117>Albert Goldfain</obo:IAO_0000117>
<obo:IAO_0000117>Alexander Diehl</obo:IAO_0000117>
<obo:IAO_0000117>Lindsay Cowell</obo:IAO_0000117>
<obo:IAO_0000118 xml:lang="en">opportunitistic pathogenic disposition</obo:IAO_0000118>
<rdfs:comment>The disposition is realized in a process by which the bearer becomes part of a disorder in an immunocompromised host.</rdfs:comment>
<rdfs:comment xml:lang="en">This includes individuals who are immunocompromised or who have damaged barriers that normally protect against infection (e.g. skin).</rdfs:comment>
<rdfs:label xml:lang="en">opportunistic infectious disposition</rdfs:label>
</owl:Class>
EDIT: I tried using rdflib to achieve this by loading the source ontology as a Graph(). Using a for loop to iterate through statements in the loaded graph, it's easy enough to find the triples which are directly connected to a class, say, ido:IDO_0000406 -> obo:IAO_0000117 -> Alexander Diehl. These can then be added to the target ontology, which is also loaded as a graph. However, using the IDO_0000406 class example, it is clear that triples not on the first sub-level (i.e. anything within the clause <rdfs:subClassOf><owl:Class>...) will not come through as expected. For example:
g_tgt = Graph()
classes = ['http://purl.obolibrary.org/obo/IDO_0000406'
'http://purl.obolibrary.org/obo/IDO_0000407',
'http://purl.obolibrary.org/obo/IDO_0000408',
'http://purl.obolibrary.org/obo/IDO_0000409']
g_src = Graph()
g_src.parse('ido.owl')
for stmt in g_src: # stmt: (subject, predicate, object)
if str(stmt[0]) in classes:
# adds all first-level triples to target graph
g_tgt.add((stmt[0], stmt[1], stmt[2]))
My thought is to approach non-first-level nodes in a recursive fashion and will update if this is successful.
EDIT 2: It should be possible to extract the classes using ROBOT (http://robot.obolibrary.org/extract). For example:
robot extract --method STAR \
--input filtered.owl \
--term-file uberon_module.txt \
--output results/uberon_module.owl
where uberon_module.txt would include the list of classes to be extracted.

How to query data from a object URI in sparql

<?xml version="1.0"?>
<rdf:RDF xmlns="http://localhost/mydata#"
xml:base="http://localhost/mydata"
xmlns:g="http://localhost/mydata/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://localhost/mydata">
<owl:imports rdf:resource="http://www.owl-ontologies.com/travel.owl"/>
<owl:imports rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
</owl:Ontology>
</rdf:RDF>
I have my RDF in the above format. I wish to query the data in the resource http://www.owl-ontologies.com/travel.owl as well. How can I do it? I get the URI value using the below query but shall be done next?
prefix ab:<http://www.owl-ontologies.com/travel.owl#>
prefix rdfs:<https://www.w3.org/2000/01/rdf-schema#>
prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix owl:<http://www.w3.org/2002/07/owl#>
SELECT ?y
WHERE { ?x owl:imports ?y.
?
}

Using the SPARQL Query tab in Protoge to query elements within my own ontology

I have an ontology that I am trying to qrite SPARQL queries for.
I'm using the Ontology IRI (http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology) displayed on the Active ontology tab to define the PREFIX value in the query below:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX chris: <http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#>
SELECT ?class ?activity
WHERE { ?class chris:hasActivity ?activity }
When I run this nothing is returned, yet when I output the ontology into RDF format I can see instances if what I want to be returned:
<owl:Class rdf:about="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#SportsHallBooking">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#BookableTimetable"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#hasActivity"/>
<owl:someValuesFrom rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#Badminton"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#hasActivity"/>
<owl:someValuesFrom rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#Football"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
So I would expect the results to include:
class | activity SportsHallBooking | Badminton
SportsHallBooking | Football
Yet I get nothing back.
Credit to Stanislav for the answer.
select * { ?class rdfs:subClassOf [ owl:onProperty chris:hasActivity; owl:someValuesFrom ?activity ] }

How can I create an owl:intersectionOf two owl:Classes?

For a school exercise, I have an RDF file and an OWL file.
There is an owl:Class Lecturer and an owl:Class Researcher. The intersection of both should be a Professor. I have put my RDF and OWL file below.
Problem is: when I do my query, no resource is of type Professor, while in the RDF file we can see that Laura should be a Professor.
Reduced version of rdf file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY humans "http://www.inria.fr/2007/09/11/humans.rdfs">
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#"> ]>
<rdf:RDF
xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd ="&xsd;"
xmlns ="&humans;#"
xml:base ="&humans;-instances" >
<Person rdf:ID="Laura">
<name>Laura</name>
</Person>
<Lecturer rdf:about="#Laura"/>
<Researcher rdf:about="#Laura">
<name>Laura</name>
</Researcher>
</rdf:RDF>
Reduced version of owl file:
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://www.inria.fr/2007/09/11/humans.rdfs"
xmlns:owl="http://www.w3.org/2002/07/owl#">
<owl:Class rdf:ID="Person">
</owl:Class>
<owl:Class rdf:ID="Lecturer">
<subClassOf rdf:resource="#Person"/>
</owl:Class>
<owl:Class rdf:ID="Researcher">
<subClassOf rdf:resource="#Person"/>
</owl:Class>
<owl:Class rdf:id="Professor">
<owl:intersectionOf rdf:parseType="Collection">
<owl:Class rdf:about="#Lecturer"/>
<owl:Class rdf:about="#Researcher"/>
</owl:intersectionOf>
</owl:Class>
</rdf:RDF>
The query I used was the defautl query:
select * where {
?x ?p ?y
}
But what I actually would expect to do is the following:
select * where {
?x a <http://www.inria.fr/2007/09/11/humans.rdfs#Professor>
}
I did look at this answer: Why do we need to use rdf:parseType="Collection" with owl:intersectionOf? but I don't understand in which way it should be used for my specific problem.
I hope somebody can help. By the way, it's my first post here, so let me know if something's missing.
Paraphrased from comments by #stanislav-kralin:
Use correct capitalization of rdf:ID (not rdf:id), and enable "OWL-Max" reasoning when loading your RDF into GraphDB.

WF4 WCF Correlation and MessageContract not working

I have a WF4 WCF service that i am trying to get correlation to work using Content based through the soap message.
I am getting the following error message:
<Message>A correlation query yielded an empty result set. Please ensure correlation queries for the endpoint are correctly configured.</Message>
<StackTrace><![CDATA[at System.ServiceModel.Activities.Dispatcher.CorrelationKeyCalculator.Calculator`1.CalculateKeys(T target, Message messageToReadHeaders, InstanceKey& instanceKey, ICollection`1& additionalKeys)
at System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.GetInstanceKeys(OperationContext operationContext, InstanceKey& instanceKey, ICollection`1& additionalKeys)
at System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult.EnsureInstanceId()
at System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult.Process()
at System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult..ctor(ControlOperationInvoker invoker, Object[] inputs, IInvokeReceivedNotification notification, TimeSpan timeout, AsyncCallback callback, Object state)
at System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.InvokeBegin(Object instance, Object[] inputs, IInvokeReceivedNotification notification, AsyncCallback callback, Object state)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)]]></StackTrace>
here is my class
[MessageContract(IsWrapped = false)]
public class ClaimObj
{
[MessageHeader]
public string CorrelationId { get; set; }
[MessageBodyMember]
public string InstanceId { get; set; }
}
here is my xaml with the namespaces changed for proprietary reasons
<Activity mc:Ignorable="sap" x:Class="Project.WorkFlow.Activities.Activity4" sap:VirtualizedContainerService.HintSize="654,676" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation" 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://ns.ns2.com/" xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:qm="clr-namespace:Project.MessageWrappers;assembly=Project.MessageWrappers" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities" 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: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">
<Flowchart sad:XamlDebuggerXmlReader.FileName="D:\Activity4.xaml" sap:VirtualizedContainerService.HintSize="614,636">
<Flowchart.Variables>
<Variable x:TypeArguments="qm:ClaimObj" Name="RequestObj" />
<Variable x:TypeArguments="p1:CorrelationHandle" Name="handle" />
</Flowchart.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">False</x:Boolean>
<av:Point x:Key="ShapeLocation">270,2.5</av:Point>
<av:Size x:Key="ShapeSize">60,75</av:Size>
<av:PointCollection x:Key="ConnectorLocation">300,77.5 300,107.5 290,107.5 290,115</av:PointCollection>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<Flowchart.StartNode>
<FlowStep x:Name="__ReferenceID1">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<av:Point x:Key="ShapeLocation">162.5,115</av:Point>
<av:Size x:Key="ShapeSize">255,90</av:Size>
<av:PointCollection x:Key="ConnectorLocation">290,205 290,235</av:PointCollection>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<p1:Receive x:Name="__ReferenceID0" CanCreateInstance="True" CorrelatesWith="[handle]" sap:VirtualizedContainerService.HintSize="255,90" OperationName="Process" ServiceContractName="p:IActivity4Service">
<p1:Receive.CorrelatesOn>
<p1:XPathMessageQuery x:Key="key1">
<p1:XPathMessageQuery.Namespaces>
<ssx:XPathMessageContextMarkup>
<x:String x:Key="xg0">http://schemas.datacontract.org/2004/07/Project.MessageWrappers</x:String>
</ssx:XPathMessageContextMarkup>
</p1:XPathMessageQuery.Namespaces>sm:header()/tempuri:CorrelationId</p1:XPathMessageQuery>
</p1:Receive.CorrelatesOn>
<p1:ReceiveMessageContent DeclaredMessageType="qm:ClaimObj">
<OutArgument x:TypeArguments="qm:ClaimObj">[RequestObj]</OutArgument>
</p1:ReceiveMessageContent>
</p1:Receive>
<FlowStep.Next>
<FlowStep x:Name="__ReferenceID2">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<av:Point x:Key="ShapeLocation">162.5,235</av:Point>
<av:Size x:Key="ShapeSize">255,90</av:Size>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<p1:SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendReplyToReceive" sap:VirtualizedContainerService.HintSize="255,90">
<p1:SendMessageContent DeclaredMessageType="qm:ClaimObj">
<InArgument x:TypeArguments="qm:ClaimObj">[RequestObj]</InArgument>
</p1:SendMessageContent>
</p1:SendReply>
</FlowStep>
</FlowStep.Next>
</FlowStep>
</Flowchart.StartNode>
<x:Reference>__ReferenceID1</x:Reference>
<x:Reference>__ReferenceID2</x:Reference>
I know the issue is with my xpath for the correlation. I have tried many different ideas and the only one that works is 11445 (http://msdn.microsoft.com/en-us/library/ee358742.aspx), but that doesn't give me the tracking with correlation. These don't work
sm:body()/xg0:ClaimObj/xg0:CorrelationId
sm:header()/tempuri:CorrelationId
sm:header()/xg0:ClaimObj/xg0:CorrelationId
sm:header()/tempuri:ClaimObj/tempuri:CorrelationId
I can get it to work with DataContracts just fine, but i need to use MessageContracts
UPDATE:
Here is what i really need to do:
Receive request
send a one way wcf call to Server X
(2nd receive) Server X sends back to workflow in a new wcf call with correlation id, not a reply
do some other stuff
send reply to original receive
Here is the basic workflow I am trying to get working. The issue is that the 2nd receive is not being called due to the xpath not being found.
on a side note, i get the same issue when i try to use correlationinitializer in the first receive
<Activity mc:Ignorable="sap" x:Class="Project.WorkFlow.Activities.Activity4" sap:VirtualizedContainerService.HintSize="828,872" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation" 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://ns.domain.com/" xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:qm="clr-namespace:Project.MessageWrappers;assembly=Project.MessageWrappers" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities" 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: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">
<Flowchart sad:XamlDebuggerXmlReader.FileName="D:\Activity4.xaml" sap:VirtualizedContainerService.HintSize="788,832">
<Flowchart.Variables>
<Variable x:TypeArguments="qm:ClaimObj" Name="RequestObj" />
<Variable x:TypeArguments="p1:CorrelationHandle" Name="handle" />
<Variable x:TypeArguments="qm:GetClaimObj" Name="GetClaimIn" />
</Flowchart.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">False</x:Boolean>
<av:Point x:Key="ShapeLocation">270,2.5</av:Point>
<av:Size x:Key="ShapeSize">60,75</av:Size>
<av:PointCollection x:Key="ConnectorLocation">300,77.5 300,107.5 290,107.5 290,115</av:PointCollection>
<x:Double x:Key="Width">773.5</x:Double>
<x:Double x:Key="Height">796.04</x:Double>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<Flowchart.StartNode>
<FlowStep x:Name="__ReferenceID1">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<av:Point x:Key="ShapeLocation">162.5,115</av:Point>
<av:Size x:Key="ShapeSize">255,90</av:Size>
<av:PointCollection x:Key="ConnectorLocation">290,205 290,209 241,209 241,239</av:PointCollection>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<p1:Receive x:Name="__ReferenceID0" CanCreateInstance="True" CorrelatesWith="[handle]" sap:VirtualizedContainerService.HintSize="255,90" OperationName="Process" ServiceContractName="p:IActivity4Service">
<p1:Receive.KnownTypes>
<x:Type Type="qm:ClaimObj" />
</p1:Receive.KnownTypes>
<p1:ReceiveMessageContent DeclaredMessageType="qm:ClaimObj">
<OutArgument x:TypeArguments="qm:ClaimObj">[RequestObj]</OutArgument>
</p1:ReceiveMessageContent>
</p1:Receive>
<FlowStep.Next>
<FlowStep x:Name="__ReferenceID2">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<av:Point x:Key="ShapeLocation">120,239</av:Point>
<av:Size x:Key="ShapeSize">242,93</av:Size>
<av:PointCollection x:Key="ConnectorLocation">241,332 240,332 240,355</av:PointCollection>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<p1:InitializeCorrelation Correlation="[handle]" sap:VirtualizedContainerService.HintSize="242,93">
<InArgument x:TypeArguments="x:String" x:Key="key1">[RequestObj.CorrelationId]</InArgument>
</p1:InitializeCorrelation>
<FlowStep.Next>
<FlowStep x:Name="__ReferenceID3">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<av:Point x:Key="ShapeLocation">112.5,355</av:Point>
<av:Size x:Key="ShapeSize">255,90</av:Size>
<av:PointCollection x:Key="ConnectorLocation">240,445 240,475 241,475 241,479</av:PointCollection>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<p1:Receive CorrelatesWith="[handle]" sap:VirtualizedContainerService.HintSize="255,90" OperationName="GetClaim" ServiceContractName="p:IActivity4Service">
<p1:Receive.CorrelatesOn>
<p1:XPathMessageQuery x:Key="key1">
<p1:XPathMessageQuery.Namespaces>
<ssx:XPathMessageContextMarkup>
<x:String x:Key="xg0">http://schemas.datacontract.org/2004/07/Project.MessageWrappers</x:String>
</ssx:XPathMessageContextMarkup>
</p1:XPathMessageQuery.Namespaces>sm:header()/xg0:CorrelationId</p1:XPathMessageQuery>
</p1:Receive.CorrelatesOn>
<p1:ReceiveMessageContent DeclaredMessageType="qm:GetClaimObj">
<OutArgument x:TypeArguments="qm:GetClaimObj">[GetClaimIn]</OutArgument>
</p1:ReceiveMessageContent>
</p1:Receive>
<FlowStep.Next>
<FlowStep x:Name="__ReferenceID4">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<av:Point x:Key="ShapeLocation">120,479</av:Point>
<av:Size x:Key="ShapeSize">242,58</av:Size>
<av:PointCollection x:Key="ConnectorLocation">241,537 240,537 240,565</av:PointCollection>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<Assign sap:VirtualizedContainerService.HintSize="242,58">
<Assign.To>
<OutArgument x:TypeArguments="x:String">[GetClaimIn.InstanceId]</OutArgument>
</Assign.To>
<Assign.Value>
<InArgument x:TypeArguments="x:String">Get is called</InArgument>
</Assign.Value>
</Assign>
<FlowStep.Next>
<FlowStep x:Name="__ReferenceID5">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<av:Point x:Key="ShapeLocation">112.5,565</av:Point>
<av:Size x:Key="ShapeSize">255,90</av:Size>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<p1:SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendReplyToReceive" sap:VirtualizedContainerService.HintSize="255,90">
<p1:SendMessageContent DeclaredMessageType="qm:GetClaimObj">
<InArgument x:TypeArguments="qm:GetClaimObj">[GetClaimIn]</InArgument>
</p1:SendMessageContent>
</p1:SendReply>
</FlowStep>
</FlowStep.Next>
</FlowStep>
</FlowStep.Next>
</FlowStep>
</FlowStep.Next>
</FlowStep>
</FlowStep.Next>
</FlowStep>
</Flowchart.StartNode>
<x:Reference>__ReferenceID1</x:Reference>
<x:Reference>__ReferenceID2</x:Reference>
<x:Reference>__ReferenceID3</x:Reference>
<x:Reference>__ReferenceID4</x:Reference>
<x:Reference>__ReferenceID5</x:Reference>
I am missing the CorrelationInitializers in your XAML. The CorrelationInitializers is used to create a correlation on the Receive or SendReply activity with the original request. After that the CorrelatesOn is used in subsequent Receive activities.
I just ran into the same problem and the article you linked to actually helped me resolve it. About 3/4 of the way down the page, there is a paragraph that reads...
If an XPath query is configured incorrectly such that no correlation
data is retrieved, a fault is returned with the following message: "A
correlation query yielded an empty result set. Please ensure
correlation queries for the endpoint are correctly configured." One
quick way to troubleshoot this is to replace the XPath query with a
literal value as described in the previous section. This issue can
occur if you use the XPath query builder in the Add Correlation
Initializers or CorrelatesOn Definition dialog boxes and your workflow
service uses message contracts.
The dialog box always generates queries that target message body properties, even when the property you select is part of the message header. The correct query to access a header property is:
sm:header()/namespace:property
Note that the property name is not qualified by the containing object, so the following query should work for you:
sm:header()/tempuri:CorrelationId
If you'd like to change the namespace of the header property, use the Namespace property of the MessageHeaderAttribute class.