Adding Custom HTTP Headers to messages send via HTTP Adapter.

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.

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

Learning WCF: A Hands-On Guide

Well Learning WCF: A Hands-on Guide has finally made it to the shelves at Amazon.  This book was highly recommended me while I was attending the BizTalk 2006 R2 Jumpstart Training back in March. I have been awaiting it’s arrival since then so you would not believe my excitement when I saw it at the TechED Store here in Orlando. I am just starting reading it and so far it has been well worth the wait.

Annual breakfast pancake fly-in photos

I took son and a friend to Mid-Way Regional airport for the annual breakfast pancake fly-in. It was second time my older son was up in the small plane and he coped very well with his fear he had on the first flight and was really excited. We got there a bit late and missed racing cars but we saw all planes, toured into DC-3, watched T-28B Trojan and T-6 Texan take-offs and other good things. On the way back we landed at Lancaster, had a lunch and sat in the L-29 cockpit owned by local pilot. One day Iwant to fly one.

The Disassembler cannot retrieve the document specification using this name…

I’ve seendevelopers stumble across this error.Complete message can look like this:

A message received by adapter “FILE” on receive location “Receive LocationTransform1” with URI “\\server001\\File.IO\ReceiveLocation1\*.*” is suspended.

Error details: There was a failure executing the receive pipeline: “MyApplication.ReceivePipeline, MySolution.Application.Pipelines, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5cf43733eafbdceb” Source: “FlatFileDisassembler” Receive Port: “ReceivePortTransform” URI: “\\server001\\File.IO\ReceiveLocation1\\*.*” Reason: The Disassembler cannot retrieve the document specification using this name: “MySolution.MyApplication.Schemas.Alpha,MySolution.MyApplication.Schemas,Version=1.0.0.0,Culture=neutral,PublicKeyToken=5cf43733eafbdceb”.

Onetypical scenario to receive this error is deploying new schema into BizTalk database and forgetting to install it into the GAC. For single server configuration it is easily avoided if assembliesare added to MSI with option GacOnImport. For multi-server deployment GacOnImport won’t be enough as it only installs assembly in the GAC of one box. You still need to run MSI on every box in the group so the GacOnInstall do the job.

Another case when you get to see this message is if one of host instances still using old version of the updated assembly. Restarting host instance(s) should easily take care of the problem. But I’ve often seendevelopers stuck in frustration. This can happen on large solutions with complex deployment structure with multiple applications, hosts and servers.Considertwo servers BizTalk group where 3 applications are deployed. Each application uses its own host which in turn has two instances (one per server). In total we have 6 host instances in this group. When one of the applications is updated its host instances should be restarted without stopping other’s applications hosts.

If applications use the same adapters (i.e. File adapter)and if per application adapter hosts were not assigned then they will be sharingcommon host for send/receiveoperations and in most cases it will bedefault BizTalkApplicationHost. In this situation it’s easy to miss restarting required host instance. To avoid this when sharing BizTalk group with multiple applications always assign your dedicated host for send and receive handlers and include corresponding host instances restart operation into post-deployment procedure.

To create adapter host open Platform Settings/Adapters of the BizTalk group administration. Select adapter and add your host as new send and receive handler to adapter configuration. Then, in application configuration, go to send port or receive location properties and select yourhost from send or receive handler dropdown.

BizTalk Adapter for Windows Workflow Foundation sample (June 2007 CTP)

Just announced at TechEd 2007 (US) – Host your Windows Workflow in BizTalk Server via the BizTalk Adapter for Windows Workflow Foundation sample (June 2007 CTP). For complete details see Paul Andrew’s blog for the complete details (http://blogs.msdn.com/pandrew/archive/2007/06/04/biztalk-adapter-for-windows-workflow-foundation-sample-june-2007-ctp.aspx).


There is a video demo of this technology by Jon Flanders here.

BizTalk Adapter for Windows Workflow Foundation sample (June 2007 CTP)

Just announced at TechEd 2007 (US) – Host your Windows Workflow in BizTalk Server via the BizTalk Adapter for Windows Workflow Foundation sample (June 2007 CTP). For complete details see Paul Andrew’s blog for the complete details (http://blogs.msdn.com/pandrew/archive/2007/06/04/biztalk-adapter-for-windows-workflow-foundation-sample-june-2007-ctp.aspx).


There is a video demo of this technology by Jon Flanders here.

Stop by Sogeti in the Partner Expo area today

If you’ve been trying to find me amidst the crowd of people at TechEd and haven’t

succeeded, then stop by the Sogeti table in the Partner Expo today between 11:30am

and 1:00pm when I will be manning the booth and talking about Vista Impact Training

and nearly anything else people would like to talk about. Of course if no one

asks me anything, then I’ll talk about what I like to talk about … BizTalk.

GenerateTypedBamApi

Long overdue but I’ve finally got around to finishing up the latest release (1.1) of the GenerateTypedBamApi tool.  You can find the new version here, if your not familar with the tool read on!


 


The GenerateTypedBamApi command line tool enables you to take a BAM Observation model represented as a Excel Spreadsheet and generate a set of strongly typed C# classes which you can then use to create and populate BAM Activities.

The native BAM API is loosely typed and therefore requires Activity Names and Activity Items to be supplied as string literals, this can be brittle especially as the observation model evolves over time and any typos, etc. will lead to runtime errors instead of compile time errors.

A strongly typed class is created for each Activity with properties for each Activity Item along with helper methods to write Activity Items to an Activity, Add References, Custom References (e.g. Message Bodies) and Continuation.

This tool uses a XSLT transform to turn the XML representing the BAM Observation Model into C# code.

For further information on how to use BAM and why you might want to use a BAM API approach over the in-bult graphical Tracking Profile Editor please Chapter 6 of my BizTalk Book: Professional BizTalk Server 2006: http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470046422.html

Example

Consider the code whoen below which demonstates the creation of a BAM Activity (called Itinerary in this case), it populates a number of Activity Items, adds a reference to another Activity and finally adds a custom reference of a message body.

As you can see from the code many string literals representing the Activity Name and Activity Items are required throughout the code, any mistakes will cause runtime errors which can be frustrating especially when you have to undeploy and redeploy your BizTalk solution. Also, if you have a medium to large scale project then you will end up with many Activities and Activity Items which can require many lines of code to be manually created each time.

    string ItineraryActivityID = System.Guid.NewGuid().ToString();
DirectEventStream des = new DirectEventStream(“Integrated Security=SSPI;Data Source=.;Initial Catalog=BAMPrimaryImport”, 1);
des.BeginActivity(“Itinerary”, ItineraryActivityID);

des.UpdateActivity(“Itinerary”, ItineraryActivityID, “Received”, System.DateTime.Now,
“Customer Name”,”Darren Jefford”,”County”,”Wiltshire”,”Total Itinerary Price”,1285);

des.AddReference(“Itinerary”, ItineraryActivityID, “Activity”, “Flight”, flightActivityID);
des.AddReference(“Itinerary”, ItineraryActivityID, “MsgBody”, “MessageBody”, System.DateTime.Now.ToString(), myXmlMessageBody);

des.EndActivity(“Itinerary”,ItineraryActivityID);


In contrast consider the code shown below which uses the Interary C# class created by this tool, each Activity Item can be set using class properties which are strongly typed and therefore checked at compile time instead of runtime. Simplified wrappers are provided around operations such as adding references and the ActivityID is stored internally once you’ve constructed the Itinerary class which saves you having to pass it each and every time. In short this code is far simpler and easier to maintain especially as Activities evolve during your development lifecycle, also for medium to large projects this code generation approach can save you having to write hundreds to thousands of lines of code!

    // Create a new Itinerary activity class, passing a GUID as the ActivityID
DirectESApi.Itinerary itin = new DirectESApi.Itinerary( System.Guid.NewGuid().ToString() );

// Begin the activity
itin.BeginItineraryActivity();

// Set activity items
itin.Received = System.DateTime.Now;
itin.CustomerName = “Darren Jefford”;
itin.County = “Wiltshire”;
itin.TotalItineraryPrice = 1285.00M;

// Commit these changes to the database;
itin.CommitItineraryActivity();

// Add a link between this Itinerary activity and another flight activity that already exists
itin.AddReferenceToAnotherActivity(DirectESApi.Activities.Flight, flightActivityID);

// Add a message body to this activity (or any other data you require)
itin.AddCustomReference(“MsgBody”, “MessageBody”, System.DateTime.Now.ToString(), myXmlMessageBody);

// End the Activity
itin.EndItineraryActivity();


 

[in]Formação: Três Dicas

[in]Formação: Três Dicas

Primeira dica: a workshop de Windows Workflow que o Bruno C%u00e2mara vai dar na Actual Training, de 19 a 22 de Junho. O Bruno (apesar de ser da concorr%u00eancia) %u00e9 muito provavelmente quem mais percebe de Workflow c%u00e1 no burgo. Recomendo vivamente este workshop.

Segunda dica: a workshop de Windows Communication Foundation que o Ant%u00f3nio Cruz vai dar na Actual Training, de 18 a 22 de Junho em p%u00f3s-laboral. O Ant%u00f3nio conhece bastante de WCF, como o blog dele deixa perceber, e este workshop deve valer a pena.

Terceira dica: ainda faltam uns meses, mas %u00e9 altura de come%u00e7ar a pensar no assunto: o TechEd EMEA 2007. O TechEd US est%u00e1 a decorrer esta semana, e como podem verificar pela agenda ou pelas sess%u00f5es dispon%u00edveis online, o programa tem muito de interessante (pessoalmente, julgo que mais interessante que em 2006). Em Barcelona %u00e9 entre 5 e 9 de Novembro, e o registo j%u00e1 abriu. %u00c9 o maior evento Microsoft na Europa, e como de costume, altamente recomendado.