Home Page › Forums › BizTalk 2004 – BizTalk 2010 › SOAP message
- This topic has 12 replies, 1 voice, and was last updated 9 years, 3 months ago by
community-content.
-
AuthorPosts
-
-
September 4, 2008 at 2:59 PM #20588
My BTS application has to pick XML file using FILE adapter. This file
contains data enclosed in SOAP envelope, e.g. there are SOAP-
ENV:Envelope, SOAP-ENV:Header and SOAP-ENV:Body elements.How can I access the Header and Body Elements seperately in my orchestration.
-
September 5, 2008 at 5:32 AM #20605
I think your best bet would be to use XPath to pull out the data. For example, you could use the xpath function in an expression shape to extract a value:
strData = xpath(soapMsg, “string(//*[local-name()=”Data”])”);
You can use the Dan Sharp XML Viewer to build and test your XPath statements: http://www.bizbert.com/bizbert/2007/11/25/DanSharp+XmlViewer.aspx. Just run the tool and open a file, then drill down in the XML tree to the data you wan, and it builds the XPath for you.
-
September 5, 2008 at 1:39 PM #20614
There is no XSD defined for this soap message, still can I do Xpath queries?
But I do I have XSD’s defined seperately for the Header and the Body.
Actually I am not sure how it will work, An example orchestration on the web?
-
September 6, 2008 at 6:17 AM #20617
Sure, you can use XPath without a schema. Here’s how it works:
1. To extract a string of data out of the message, you could create an orchestration string variable called strData.
2. Add an expression shape to the orchestration.
3. Inside the expression shape, set the value of strData by calling the xpath() function. Ex:
strData = xpath(soapMsg, “string(//*[local-name()=”Data”])”);
The first parameter is the message to query. The second parameter is the actual XPath query. Here is a good article on the xpath() function: http://geekswithblogs.net/sthomas/archive/2004/10/25/13269.aspx. Since you have schemas for the header and body, you may want to pull the header and body out of the SOAP message at the beginning of the orchestration, and then work directly with the header and body messages. Then you could define distinguished fields in the schemas. Distinguished fields allow you to access the data in a cleaner fashion. Ex:
strData = bodyMessage.Data;
-
September 8, 2008 at 4:30 PM #20642
Hi Russel,
Thank you so much for the reply. I tried whatever you said and it works.
But, I have follow up question, How I pull the header and body out of the SOAP message as you explained. It seems to be the correct way for me.. Could you please explain..
-
September 9, 2008 at 7:06 AM #20645
Sure. You just need to create 2 new messages in your orchestration, 1 for the header data and 1 for the body data. Then in a message assignment shape, you can use XPath to extract the data from the SOAP envelope and assign it to the messages. Ex:
msgHeaderData = xpath(soapEnvIn, “/*[local-name()=’Envelope’]/*[local-name()=’Header’]/*[local-name()=’HeaderData’]”);
msgBodyData = xpath(soapEnvIn, “/*[local-name()=’Envelope’]/*[local-name()=’Bodyr’]/*[local-name()=’BodyData’]”);
Note: This example assumes that the data that you want from the SOAP envelope is stored in nodes named “HeaderData” and “BodyData”. This is probably not the case, so your actual xpath will be a little different.
-
September 18, 2008 at 11:55 AM #20765
Hi Russell,
It took me some time to try what you explained me here.
I created inMessage with Message type XMLDocument.
I created envMessage with MessageType of BTS.soap_envelope_1__1.Envelope
I created two messages hdrMessage with message type as header schema , cntMessage with message type as content schema.
In the message assignment shape, I have assigned
envMessage = inMessage
hdrMessage = xpath(envMessage,…)
cntMessage = xpath(envMessage,..)
In my schemas(header and content) I have some distinguised fields
So When I tried to get the values based on the distinguised fiels nothing come out..
What am I missing..
-
September 18, 2008 at 12:32 PM #20767
Maybe your XPath queries aren’t bringing back anything. Have you tested them? You can use the XPath tool that I mentioned above. Just run the tool, open the SOAP envelope file, paste the XPath into the tool, and test the XPath.
By the way, it is not necessary to create the envMessage to use the xpath() function. You can run XPath directly against the inMessage. However, the envMessage may have distinguished fields for the header and body. If so, it might be easier just to use the distinguished fields to get the header and body data than using xpath().
-
September 18, 2008 at 1:06 PM #20769
Hi Russell,
My Xpath queries are returning the data. I am actually using the tool that you suggested.
But, when I use the distinguished fields method, I don’t get any data. I mean I wnat to use the schemas provided and make use of the distinguised fields, How can I do that.
-
September 18, 2008 at 1:18 PM #20771
If your distinguished fields are coming up empty, I would suspect that either those fields in the XML are empty, or the whole message is empty. Try writing out the message somewhere like to a file or the debug console. If the message is empty, then that means your xpath is probably not working in BizTalk. Sometimes you can get an xpath working in the tool, but then when you run it in BizTalk it doesn’t work because the incoming message gets transformed or modified somehow. If the incoming file is being modified, you would need to write it out somewhere, and then load it up in the tool and test the xpath on it.
-
September 18, 2008 at 1:40 PM #20772
Thank you so much for your prompt replies, Russell.
I am actually writing the messages to EventLog, my xpath queries are returning good data. But when I attempt to achieve the same by distinguished fields .. then no data.
If you don’t mind, would you let me know the steps once gain to do this.. I think I miss something..
-
September 18, 2008 at 2:33 PM #20773
What are you extracting with distinguished fields? Is it data from your message, or are you trying to use the distinguished fields to extract the messages from the SOAP envelope? Distinguished fields are just canned xpath statements, so they can come up empty if you use them on an invalid message. Make sure your message is valid by writing it out to a file, and then validating it against your schema. If it is valid, then maybe it’s a problem with the fields themselves. Try un-distinguishing the fields and then re-distinguishing them.
-
September 19, 2008 at 8:34 AM #20780
I am trying to extract data from distinguished fields.
Actually I want to validate the Header part with the header schema and Body part with the Content schema that are defined seperately for the Soap Message.
Then I want to get the data out of the messages using distinguihsed fields.
-
-
-
-
-
-
-
-
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.