Adding Custom HTTP Headers to messages send via HTTP Adapter.

Posted at: 6/6/2007 at 10:14 PM by saravana

Download Full sample code here

There will often be times we need to add some custom HTTP Headers to our outgoing message. The common one we come across is SOAPAction, if you need to communicate with the web services just with HTTP adapter (not using SOAP Adapter).

BizTalk server gives us a context property called "UserHttpHeader" as part of the HTTP adapter, which can be used to set custom HTTP headers.

The below Orchestration shows an example, how you can take advantage of "UserHttpHeader" property.

image

The code inside the "Message Assignment" shape is shown below:

MSG_AUTHOR_OUT = MSG_AUTHOR_IN;
MSG_AUTHOR_OUT(*) = MSG_AUTHOR_IN(*);
MSG_AUTHOR_OUT(HTTP.UserHttpHeaders) = "userName: Saravana\r\npassword: hola";

Important things to note:

  1. You can add multiple headers (ex: userName, password) in a single line as shown in the sample above.
  2. "\r\n" is used to separate multiple headers.
  3. ": " is used to separate header and value, you must specify a SPACE after colon.

The content of the output file is shown below

POST /HTTPReceiver/Default.aspx HTTP/1.1
Connection: Keep-Alive
Content-Length: 312
Content-Type: text/xml; charset=utf-16
Expect: 100-continue
Host: localhost:3131
User-Agent: Microsoft (R) BizTalk (R) Server 2006 3.0.1.0
userName: Saravana
password: hola

<?xml version="1.0" encoding="utf-16"?><<stripped content for clarity>>

I used an orchestration sample to demonstrate how you can set UserHttpHeader context property. But like any other BizTalk context property you can set this property in different places like within custom adapter, custom pipeline etc.

Download Full sample code here

Nandri!

Saravana

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

Comments

Monday, October 08, 2007 12:30 PM
Anonymous
Anonymous
Nice example Kumar. Thanks for sharing this info!
Monday, January 05, 2009 7:50 AM
Sam United States
Sam
Hi Sarvana,

I'm a bit new to this, I tried this an get an error. Here is my assignment
SaadRqMsgHeaders = SaadRqMsg;
SaadRqMsgHeaders(*) = SaadRqMsg(*);
SaadRqMsgHeaders(HTTP.UserHttpHeaders) = "CONTENT-TYPE: application/octet-stream\r\nsender-id: BSARI\r\nreceiver-id: SAAD-001\r\ndestination-id: 401\r\nrquid: 25b922c4-0f11-4d6a-953d-4ba559c6f0b8";

It compiles fine

but I get a run time error of
A message sent to adapter "HTTP" on send port "SaadSendInq" with URI "https://unit-test.com.ed:5400/invoke/SAADEX01Query.Accept/query" is suspended.
Error details: This header must be modified using the appropriate property.
Parameter name: name

Any idea why?

Thanks
Tuesday, January 27, 2009 1:07 AM
James United States
James
headers can be hard to know if they are setup correctly - you should use a tool like Mozilla firefox + live headers plugin - or you can use a web based tool like http://www.httpviewer.net/

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading