Sending Parameters with the BizTalk HTTP Adapter

Posted by Christopher House on Geeks with Blogs See other posts from Geeks with Blogs or by Christopher House
Published on Thu, 20 May 2010 07:51:41 GMT Indexed on 2010/05/20 15:02 UTC
Read the original article Hit count: 594

Filed under:

I've never had occaison to use the BizTalk HTTP adapter since I've always needed SOAP rather than just POX (plain old XML).  Yesterday we decided that we're going to expose some data via a Java servlet that will accept an HTTP post and respond with POX.  I knew BizTalk had an HTTP adapter but I had no idea what it's capabilities were.

After a quick read through the BizTalk docs, it was apparent that the HTTP send adapter does in fact do posts.  The concern I had though was how we were going to supply parameters to the servlet.  The examples I had seen using the HTTP adapter all involved posting an XML message to some HTTP location.  Our Java guy, however didn't want to take that approach.  He wanted us to provide a query string via post, much like you'd expect to see on an HTTP get. 

I decided to put together a little test scenario and see what I could come up with.  We didn't have a test servlet I could go against and my Java experience is virtually nill, so I decided to put together an ASP.Net project to act as the servlet.  It didn't need to be fancy, just one HttpHandler that accepts a post, reads a parameter and returns XML.  With the HttpHandler done, I put together a simple orchestration to send a message to the handler.  I started by having the orch send a message of type System.String to see what it would look like when the handler received it.

I set a breakpoint in my handler and kicked off the orchestration.  Below is what I saw:

HttpHandler Receive

As I suspected, because of BizTalk's XML serialization, System.String was not going to work.  I thought back to my BizTalk 2004 days and I project I worked on that required sending HTML formatted emails via the SMTP adapter.  To acomplish that, I had used a .Net class with a custom serialization formatter that I got from a Microsoft sample.  The code for the class, RawString can be found here.

I created a new class library with the RawString class as well as a static factory class, referenced that in my orchestration project and changed my message type from System.String to RawString.  Below is what the code in my message construction looks like:

Message Construction

After deploying the updated orchestration, I fired it off again and checked the breakpoint in my HttpHandler.  This is what I saw:

HttpHandler breakpoint

And there you have it.  The RawString message type allowed me to pass a query string in the HTTP post without wrapping it in XML.

© Geeks with Blogs or respective owner