Click here to Skip to main content
6,822,123 members and growing! (17,533 online)
Email Password   helpLost your password?
Enterprise Systems » Microsoft BizTalk Server » General     Intermediate License: The Code Project Open License (CPOL)

Parsing BizTalk Messages in .NET Components through Orchestration

By Abdul_Rafay

Parsing BizTalk messages in .NET Components through Orchestration
C#, .NET
Revision:2 (See All)
Posted:2 May 2009
Views:2,772
Bookmarked:6 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
0 votes for this article

Introduction 

In most of our orchestrations where we need to parse a message, let's say for storing data from the message in a database to loop through the records in the message, we use XML Parsing. For that we have XpathNavigator class or we can use XMLDocument SelectNodes method which returns an iterator and we can iterate the records in the XML. But consider a complex XML for example. If there are many parent child nodes and we have to dig deeper into the nodes, come back again to the parent and use nested while loops for parsing the whole XML. Well for a good coder, this won't be much of a problem but a messy coder like me will run into exceptions and bugs. :)

Well how about if we take advantage of .NET Serialization/Deserialization? We pass the message as an XMLDocument object to our component method as a parameter we deserialize the xmldocument to an object. But wait, which object? From where will its class come from? We just need a proxy class of the web message type. The proxy class will contain the web message type and all of its nodes and then we can deserialize the xmldocument object containing the XML into a much managed object which we can iterate easily. You can generate the proxy class from Visual Studio command prompt and giving the proper switches will create the proxy class.

You can see the MSDN help for more switches of WSDL.

wsdl /out:[dir]proxy.cs http://localhost/[webservice URI].asmx?wsdl 

If you notice, the webservice URI is missing from the command and we need a wsdl of the web service. A simple workaround for this is in our BizTalk Schema project which contains the type of message (schema) which is built and then a web message should be published from the BizTalk Web Services Publishing Wizard. Just build your project and run the wizard. In the first step, select the "Publish schemas as web services" option. You will get a tree in the next step and yes the web service requires at least a request and response schemas.

web_pub_1

Right click the request schema and select the assembly. (This assembly should be your BizTalk schemas project.) 

choose_schema

Select the root node of your schema, in the same way configure the response message as well (of your own choice) and you are done.


web_pub

In the next step, give the URI of the web service and then the hierarchy in your IIS.

By running the command given above, you will get the proxy class. Include this class in your component project (which will be most likely a .NET library project). (Note: If you don't see your schema type class in the intellisense, do check the proxy class and your component project namespaces). In your components method which will be parsing your message, deserialize your xmldocument object to the object type of the proxy class. This will be the Root node (If you have one) name of your schema. In my case, I used the code below. Xdoc is the object variable name of the type XMLDocument which will contain my XML data. And one more thing which I am sure most of the BizTalk guys will know is you can assign your message freely to the XMLDocument type variable in your orchestration.

IFX response = new IFX(); 
XmlSerializer xs = new XmlSerializer(response.GetType());
XmlNodeReader reader = new XmlNodeReader(xdoc.DocumentElement,"Namespace"); 
response = (IFX)xs.Deserialize(reader); 

In the above code, I was receiving a response and wanted to insert the records from the response into my table. This made me comfortably access the inner child records and arrays of the XML. Maybe you would get XML document runtime errors. Do check your XML that if it contains namespaces then deserialization will give exceptions. For this supply the namespace of the root node in the XmlNodeReader constructor.

You can find the original post .

History

  • 2nd May, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Abdul_Rafay


Member
I am currently developing and designing BizTalk solutions at a Bank in Riyadh, Saudi Arabia. Prior to this position I worked as a BizTalk Applications developer at a Bank in Karachi, Pakistan.

After graduating from University of Karachi in 2007 I decided to work as consultant in a Bank on BizTalk where I started learning the technology.Developing BizTalk applications for SOA is a good experience after working on desktop and web applications in .NET and other platforms. While learning the technology I have come accross various technical, architecture and performance based scenarios in my Enterprise.

Besides BizTalk, I have a vast experience in developing and designing from middle to large scale web applications mailnly on ASP.NET 1.1/2.0 and PHP and have customized open source web solutions. During my last year of graduation I worked as a full time web developer for a company in Pakistan and I am learning and working on .NET since 2005. Still I work and enjoy my weekend freelance web projects.

I achieved MCTS certification in BizTalk Application development in June 2008.

Click here to check out my Blog.
Location: Saudi Arabia Saudi Arabia

Other popular Microsoft BizTalk Server articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 2 May 2009
Editor: Deeksha Shenoy
Copyright 2009 by Abdul_Rafay
Everything else Copyright © CodeProject, 1999-2010
Web20 | Advertise on the Code Project