Calling Web Service from BizTalk 2006 in a Messaging only Scenario (aka Content based Routing)

Posted at: 1/31/2007 at 6:45 PM by saravana

In this article I'll explain how you can call a Web Service which requires multiple arguments using a Custom pipeline and a custom pipeline component in a messaging-only scenario without using any Orchestration.

 

Normally, when there is a requirement to call a web service from BizTalk, people tend to take the easy route of calling it via an Orchestration. When we do a web reference inside the orchestration, Orchestration does quite a lot of work for us. It creates all the required schemas, it creates all the required multipart messages, which will be passed to the web service as argument. It makes our life easier. But I guess like me, some of you out there might need to call the web service without using Orchestration. As shown in the above figure. I've one request-response HTTP receive port, and one Solicit response SOAP send port, through this I'm going to call a web service, which expects multiple argument (including one complex type) and return the result back to the caller (HTTP Response). Here are the steps: The attached sample file contains all the required file, I'm just going to explain the key factors in this article.

1. Web Service Definition:

[WebMethod]
public Person GetPersonInfo(Person person, string firstName, string secondName) {
//Some processing
return person;
}

2. Create a general custom pipeline component to construct the multipart message required for the Web Service call 

At run time SOAP Adapter in the send port will map the Biztalk multipart IBaseMessage to the Web Service argument based on the partName of IBaseMessage and argument names of the Webservice. The key factor is how we are going to construct the multipart message in the format required by the SOAP Adapter to make the WebService call. In my previous article I explained how you can easily generate the required IBaseMessage with help of MIME message and MIME Decoder component. But when it comes to reality we don't want to get into another data format like MIME. So, in this article we are going to create custom pipeline component which will construct the correct IBaseMessage required by the SOAP adapter based on the input message and some pipeline design time properties (for more detail on design time properties see my white paper ) .

The custom pipeline component we are going to use has 2 design time properties FirstName and SecondName, which will be passed as parameters to the web service (See webservice definition from Step 1). We'll pass the first webservice argument "Person" as the incoming message via HTTP receive port. The figure below show the custom design time properties configuration window within Biztalk Admin console. 

The code below is the snippet from the custom pipeline component (two important methods Execute and CreateMessage). The Execute method below without the first line of code will be equivalent to a PassThru pipeline component with default Biztalk IBaseMessage. 

#############################################################

public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
{
IBaseMessage msg = CreateMessage(inmsg.BodyPart.GetOriginalDataStream(), pc.GetMessageFactory(),inmsg.Context);
return msg;
}

#############################################################

IBaseMessage CreateMessage(Stream s, IBaseMessageFactory msgFactory, IBaseMessageContext context)
{
IBaseMessage msg = msgFactory.CreateMessage();
IBaseMessagePart part = msgFactory.CreateMessagePart();
part.Data = s;

msg.AddPart("Person", part, true);
msg.Context = context;

//1st Part
IBaseMessagePart partFirstName = msgFactory.CreateMessagePart();
byte[] firstPart = System.Text.Encoding.UTF8.GetBytes(string.Format("<string>{0}</string>", _firstName));
partFirstName.Data = new MemoryStream(firstPart);
partFirstName.Charset = "utf-8"
partFirstName.ContentType = "text/xml"
msg.AddPart("firstName", partFirstName, false);

//2nd Part
IBaseMessagePart partSecondName = msgFactory.CreateMessagePart();
byte[] secondPart = System.Text.Encoding.UTF8.GetBytes(string.Format("<string>{0}</string>", _secondName));
partSecondName.Data = new MemoryStream(secondPart);
partSecondName.Charset = "utf-8"
partSecondName.ContentType = "text/xml"
msg.AddPart("secondName", partSecondName, false);
return msg;
}

#############################################################

Our user defined function CreateMessage will create the required BizTalk IBaseMessage as shown in the below figure

In the above code snippet, the important things to note are highlighted in RED. The incoming message ("Person") will go as the first part (BodyPart) of the IBaseMessage with the name "Person", and then we added two more addional parts "firstName" and "secondName" to the IBaseMessage with correct partNames inline with the web service arguments. The other important thing to note is how the basic data types gets serialized. In our example we got "<string>{0}</string>" as value for firstName and secondName, because they are of type string. If for example you got int as your argument then you need to create the part in the format <int>5</int>.

NOTE: See the web service signature defined in Step 1 for comparison

3. Create a Custom Receive Pipeline using the custom pipeline component

Create a new Biztalk Receive Pipeline and place the custom pipeline component we created in the "Decode" stage of the pipeline.

4. Configure the ports

As shown in our design diagram at the beginning we need 2 ports to send and receive the message, the attached sample file got a binding file, this section is just for explanation, doesn't explain in detail how to configure the ports. Make sure the URL are correct, both on Receive and Send side after importing the binding. You need to configure IIS as well to receive messages via HTTP, follow the link to configure IIS for HTTP receive  http://msdn2.microsoft.com/en-us/library/aa559072.aspx.

Two-Way HTTP Receive Port:

Solicit-Response SOAP Send Port:

We used the .NET Proxy class on our SOAP port to make the call.

Filter Condition on the Send Port

5. Post a Message.

I used WFetch to post the message to BizTalk. You can see on the result pane the request message is posted and you got the response back from the web service synchronously on a two way connection.

Troubleshooting:

Some of the common exceptions you'll see while calling a webservice via SOAP adapter is shown below (from HAT and eventviewer)

1. "Failed to retrieve the message part for parameter "firstName". "

2. "Failed to serialize the message part "firstName" into the type "String" using namespace "". Please ensure that the message part stream is created properly."

The reason for the first error message is due to wrongly named IBaseMessage partName. Read Section 2 carefully to overcome this error.

The reason for the second error message is mainly due to some problem with serializing the IBaseMessage parts to the correct web service arguments. Best approach to overcome this error will be to build a .net console/windows application, add a web reference to the webservice and try to serialize each argument to the corresponding type. For example for this example you can try the following

FileStream fs = new FileStream(@"C:\Documents and Settings\SaravanaK\Desktop\FailedMessages\_Person.out",FileMode.Open,FileAccess.Read);
XmlSerializer serialise = new XmlSerializer(typeof(LH.WebReference.Person));
LH.WebReference.Person per = (LH.WebReference.Person)serialise.Deserialize(fs);
fs.Close();

fs = new FileStream(@"C:\Documents and Settings\SaravanaK\Desktop\FailedMessages\_secondName.out",FileMode.Open,FileAccess.Read);
serialise = new XmlSerializer(typeof(string));
string s2 = (string)serialise.Deserialize(fs);
fs.Close();

The files "_Person.out" and "_secondName.out" are saved from HAT tool. See the exception detail and fix the issue, it will be some namespace issue or data issue.

DOWNLOAD SAMPLE

Read the readme.txt file inside to configure it. Will take approximately 5-20 minutes based on your BizTalk knowledge level.

Related Post

In one of my previous post I explained how to call a web service that has more than one argument using a MIME message in a Content based routing(messaging only) scenario.

Nandri!

Saravana Kumar

Tags: | |  Categories: BizTalk 2006 | BizTalk General
Actions: Email this article Email | Kick it! | DZone it! | Save to del.icio.us | Technorati Links
Post Information: Permanent LinkPermalink | CommentsComments(53) | Comments RSS

Comments

Wednesday, February 14, 2007 7:12 PM
Sundar Rajan
Hi Saravana,

Very good article. I just have one question related to this topic. I am trying to call an XML Web Service (created using VS.NET 2003) within Biztalk 2006 orchestration. When I add the Web Reference the Reference.xsd file is not created while all other files Reference.map, Reference.odx, wsdl and disco files are created. Without Reference.xsd I cannot do any mapping. How to do this.
Wednesday, February 14, 2007 7:13 PM
Sundar Rajan
Monday, February 19, 2007 5:30 PM
Saravana Kumar
Hello Sundar, I hope you would have solved this problem by now. Adding a Web Reference to a Web Service is quite straight forward process within you orchestration project. As soon as you reference the webservice, you should see all the xsd files named something like lc.xsd, lc0.xsd, lc1.xsd etc. In addition to that you'll see Reference.map under which you'll see all the Reference.* files.

If you still have the issue let me know. With you explanation I'm not able to identify your problem.
Thursday, March 01, 2007 5:08 AM
Adriaan
Adriaan
Hi Sundar. thanks for this good post.

I have an orchestration that consumes an Authentication WebService. The Websvc returns a sessionID GUID as a custom property inside the SOAP header response. I need to promote this to property so I can correlate when submitting to another WebSvc ,passing the sessionid in the other SOAP header.

Do you have any idea where I should start ? Regards Adriaan
Wednesday, March 07, 2007 3:12 PM
Rajeev
Hi It is really a great post bt I need some help. I have created a web service in Dot Net 2005 that has a web methid that takes one input and it is a customer id that is a string and returns a dataset that contains customer name address etc.

I dont want to use any orchestration I want to achiev this by pure messaging so i created a File adapter to receive an xml file with one parameter as Customerid and a string value and I have a soap adapter that calls the web method but when I submit the file it gives me an error cannot serialize to tye string.

Please can you guide me in this
Wednesday, March 07, 2007 6:33 PM
Saravana Kumar
Hello Rajeev, thats one of the common errors you see when you try to call a Web service via soap adapter on a messaging only scenario. Did you work out the sample of this post, the example i used got a string parameter as well. When you are creating the IBaseMessage inside your pipeline, you need to make sure the part content for the string is populated like this
string.Format("<string>{0}</string>", _firstName).

Nandri!
Saravana
Friday, March 09, 2007 7:24 PM
Rajeev
HI thanks for your response I tried your approach and it worked for me but I guess there is a limitation here we need to specify the firstname value in the pipeline properties but if I want to pick it from the xml schema what is the approach that I should take
Friday, March 30, 2007 3:45 PM
Gar
Gar
Hi Saravana,
Great article I'm wondering how you approach calling a web service that has customer SOAP headers e.g. a UserCredentials Header with a userName and password. Is it simply  case of creating another messagePart with the Credentials or does it need to get added in anywhere else.

Regards
Gar
Wednesday, June 13, 2007 3:24 PM
Saravana
Hello Saravana
Can i call webservice which has only request method since we dont want to get response from Web services.
Thanks
Saravana ramkumar
Friday, October 12, 2007 6:25 PM
praveen
hi saravana,
   thsi is kumar, i read the article its awesome, i got a question what happens when we call web service from orchestration --  will the meaassage be serliazed everytime you call the web service????  please do mail me if you anwser at pmognti@gmail.com
Friday, October 26, 2007 5:25 PM
Scott Brown
I wrote a small article about adding SOAP headers that addresses some of the comments on this post.

biztalkspeaks.blogspot.com/.../...-in-biztalk.html
Wednesday, November 07, 2007 9:51 AM
Anonymous
Anonymous
Still didn't get what Sundar rajan's resolution was. I created a sample WebService and imported to Biztalk. It doesn't generate the xsd. My service takes a number and returns the square of it. Please post ur comment.. I would follow up
Wednesday, November 07, 2007 9:58 AM
Saravana Kumar
For basic data types like int, double you don't need schemas (XSD). If you have complex custom types like example Person, Employee, Purchase order etc as input/output then xsd will be created. For basic types you can assign them directly within an expression shape.

Regards,
Saravana
Thursday, January 17, 2008 1:35 PM
Hari
Hari
Hi Saravana,

I need to call web service from orchestration.I have only wsdl with me.When i do web reference it fails during compilation.THis is because the generated reference.xsd is not valid.
Please help me to solve this.

Thanks
Hari
Monday, July 12, 2010 3:56 PM
faxless loans
Small opportunities are often the beginning of great enterprises
Thursday, July 22, 2010 1:45 AM
Supra Skytop NS Black Patent

<h1><a href="www.bestsuprashoes.us/supra-skytop-mens-tuf-green-p-167.html"><strong>Supra Skytop TUF Green</strong></a>, Supra Skytop TUF Green</h1><br><br />
<h1><a href="www.bestsuprashoes.us/supra-skytop-ns-black-green-white-p-168.html"><strong>Supra Skytop NS Black</strong></a>, Supra Skytop NS Black</h1><br><br />
<h1><a href="www.bestsuprashoes.us/supra-skytop-ns-black-patent-studded-p-169.html"><strong>Supra Skytop NS Black Patent</strong></a>, Supra Skytop NS Black Patent</h1><br><br />
Saturday, July 31, 2010 10:32 AM
传奇私服
Panel Advises Reprimand for Rangel, Not Expulsion http://www.iqwyx.com
Debate Heating Up on Plans for Mosque Near Ground Zero http://www.iqwcs.com
There May Be ‘No Better Place,’ but There Is a Better Slogan http://www.kicksf.com
Army Broadens Inquiry Into WikiLeaks Disclosure http://www.sf9458.com
In Maine Village, Lobster Goes Briskly; Traffic, No http://www.9kcq.com
Monday, August 02, 2010 1:10 AM
lenen
BKR problemen? Nu Geld lenen zonder BKR toetsing? Op zoek naar betrouwbare aanbieders? Wij vergelijken banken die u toch kunnen helpen aan een betrouwbare
Monday, August 02, 2010 7:51 AM
radii shoes
<h1><a href="www.radii-420.com/radii-straight-jacket-skate-board-fashion-shoe-white-silver-p-77.html"><strong>Radii Straight Jacket white silver</strong></a>, Radii Straight Jacket white silver</h1><br><br />
<h1><a href="www.radii-420.com/radii-straight-jacket-top-fashion-sneakers-black-zebra-aqua-p-78.html"><strong>Radii Straight Jacket Black Zebra Aqua</strong></a>, Radii Straight Jacket Black Zebra Aqua</h1><br><br />
<h1><a href="www.radii-420.com/radii-strangler-lifestyle-shoes-black-orange-p-79.html"><strong>Radii strangler black orange</strong></a>, Radii strangler black orange</h1><br><br />
Tuesday, August 03, 2010 9:51 AM
Gucci outlet
Very thank for sharing your posts and you review.[url=http://www.guccisaleoutlet.com/]Gucci outlet[/url]Gucci Salemany people have replyed here,and i would like to take part in.I'd like to share a Proverb with each
other one here that is:Every day of thy life is a leaf in thy history.[url=http://www.cheap-shoesonline.com/]cheap shoes online[/url] A Proverbs wiht great sense,i hope everyone would learn something from it.
[url=http://www.cheap-shoesonline.com/]cheap shoes online[/url]  cheap shoes online
[url=http://www.guccisaleoutlet.com/]Gucci Bags[/url]  Gucci Bags
[url=www.cheap-shoesonline.com/.../]Nike Air Max[/url]  Nike Air Max
[url=www.cheap-shoesonline.com/.../]cheap designer sunglasses[/url]  cheap designer sunglasses
[url=http://www.guccisaleoutlet.com/]Gucci Outlet[/url]  Gucci Outlet
Wednesday, August 04, 2010 8:17 PM
ooty
thanks for sharing the info
Wednesday, August 04, 2010 8:18 PM
jobs
good explanation thanks
Thursday, August 05, 2010 1:44 AM
Seattle Limo
I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
Thursday, August 05, 2010 6:39 PM
Legalsounds
This is my first time I have visited here. I found a lot of interesting stuff in your blog. From the tons of comments on your articles, I guess I am not the only one! keep up the great work.
Saturday, August 07, 2010 3:51 PM
Cam Chat
You really know your stuff... Keep up the good work!
Saturday, August 07, 2010 4:19 PM
Sex Chat
This is such a wonderful useful resource that you'll be providing and you provide it away for free of charge
Tuesday, August 10, 2010 12:25 AM
hypotheek
Hypotheek informatie, hypotheek aanvragen of afsluiten? Hypotheekrentes bekijken. Hypotheek aanbieders vergelijken, hypotheek vormen, bijkomende kosten,
Wednesday, August 11, 2010 8:51 AM
dual sim
http://www.efox-shop.com

I read a lot of posts today and yours is the best one i have read ever.I appreciate your attitute
more info please visit the web for b2c iphone etc.
Ein seltenes Angebot: Im Handy-Shop des Mobilfunkbetreibers E-Plus steht
zurzeit das Dual-SIM-Handy Samsung B5722. Das Mobiltelefon für den parallelen
<a href="www.efox-shop.com"><b>Ciphone</.../a>
Thursday, August 19, 2010 3:39 PM
传奇私服
This pain, only you know. I always like such a lonely night, nothing at the past, those who are themselves deeply buried heart of the past, received, owned, lost, feeling a kind of come to realize a dream. Have always understood that it is wrong to indulge in the past, should not forget to remember, to forget everything, so easy to exchange for short.
http://www.5kcq.com/
http://www.cc-sf.com/
http://www.iqwlj.com/
http://www.iqwkk.com/
http://www.aa-sf.com/
http://www.iqwcs.com/
Wednesday, August 25, 2010 9:39 AM
p90x
[url=http://www.super-p90x.com/]P90X Workout DVDs[/url]
[url=http://www.super-p90x.com/]P90X Workout[/url]
[url=http://www.super-p90x.com/]P90X[/url]
[url=http://www.super-p90x.com/]P90x reviews[/url]
[url=http://www.perfectwatchs.net/]Replica Watches[/url]
[url=http://www.perfectwatchs.net/zenith]Zenith Replica Watch Revolution[/url]
[url=http://www.perfectwatchs.net/zenith-defy]Replica Zenith defy[/url]
[url=http://www.perfectwatchs.net/zenith-el-primero]Replica Zenith el-primero[/url]
[url=http://www.perfectwatchs.net/zenith-elite]Replica Zenith elite[/url]
Wednesday, August 25, 2010 9:59 AM
diana
<a href="http://www.auto-ok-erlangen.com">P90x extreme home fitness program</a>
<a href="http://www.rosetta-stone-shop.org">Rosetta Stone Spanish (Latin America)</a>
<a href="http://www.itunes-gift-card.org">itunes gift card,itunes code</a>
Thursday, August 26, 2010 7:41 PM
sell my house
Good informative post. I will visit your site often to keep updated.
Thursday, August 26, 2010 7:42 PM
buy my house
great and interessting post
Thursday, August 26, 2010 7:42 PM
buy my house
i bookmarked your blog, keep posting good stuff Smile
Friday, August 27, 2010 10:23 AM
digital radio
Thanks for the article. I almost passed your site up in Yahoo but now I'm glad I clicked the link and got to browse through it. I'm definitely more informed now. I'll be sharing your site with some other people I know. They'll for sure enjoy the heck out of what I just read too. LOL. --Jax
Friday, August 27, 2010 10:35 PM
HackingEdgecom
Thanks very much for your wonderful post;this is the stuff that keeps me going through out these day. I've been looking around for your site after being referred to them from a buddy and was thrilled when I found it after searching for long time. Being a demanding blogger, I'm happy to see others taking initivative and contributing to the community. I just wanted to comment to show my appreciation for your website as it is very enticing, and many writers do not get authorization they deserve. I am sure I'll visit again and will spread the word to my friends.
Tuesday, August 31, 2010 10:51 PM
french press coffee maker
When are you going to post again? You really inform me!
Tuesday, August 31, 2010 11:09 PM
brand reputation management
Just discovered this site thru Google, what a pleasant shock!
Tuesday, August 31, 2010 11:48 PM
toshiba netbooks
This really answered my problem, thank you!
Wednesday, September 01, 2010 12:50 AM
restaurants in the woodlands
Have you considered adding some videos to your article? I think it will really enhance my understanding.
Wednesday, September 01, 2010 5:06 PM
New Jersey Educational Consultant
Amazing article, thank you, I will subscribe to you RSS soon!
Wednesday, September 01, 2010 5:22 PM
Christina Hendricks Measurements
I'm getting a javascript error, is anyone else?
Wednesday, September 01, 2010 5:23 PM
Eugene
This really solved my problem, thank you!
Wednesday, September 01, 2010 5:57 PM
Oklahoma Military Bases
Have you thought about adding some relevant links to the article? I think it will really enhance my understanding.
Wednesday, September 01, 2010 6:06 PM
Sc2 hotkeys
Brilliant, cheers, I will visit again soon.
Wednesday, September 01, 2010 6:15 PM
warcraft leveling
Awesome post . Thanks for, writing on this blog mate! I'll message you soon. I didn't realise that!
Wednesday, September 01, 2010 7:56 PM
Ask the Doctor
Dude. This blog is cool! How can I  make it look like this ?
Wednesday, September 01, 2010 7:57 PM
Stock Market Picks
Have you thought about adding some differing opinions to the article? I think it will really enhance my understanding.
Wednesday, September 01, 2010 7:58 PM
money making ideas
Have you thought about adding some videos to your article? I think it will really enhance everyone's understanding.
Wednesday, September 01, 2010 8:19 PM
life insurance settlement
Just discovered this blog thru Google, what a way to brighten up my month!
Thursday, September 02, 2010 8:09 PM
Neda Shisler
of cause I also read your old post as this one ,<a href="http://carboyer.com.tw/">徵信社</a>還有<a href="http://170.detectivehit.com.tw/">婚前徵信</a>以及<a href="http://www.hualien-bnb.com/">花蓮民宿</a>跟一些<a href="http://168.super-detective.com.tw/">徵信</a>的服務

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading