Why BizTalk

Some people still ask me why BizTalk, they say that they can spin up a windows service and do most of the stuff !!!, i basically tell them following OOB features apart from the main ones, and they say………………………………… oh

  1. Transactional pipelines
  2. Recoverable pipelines
  3. Pipelines that call the BAM interceptor API
  4. BizTalk Server adapter support
  5. Batching
  6. Retries
  7. Correlation set initialization
  8. Declarative configuration
  9. Secondary transports
  10. Tracking
  11. Declarative use of BAM

Extending Windows Azure BizTalk Services Using Message Inspectors

Extending Windows Azure BizTalk Services Using Message Inspectors

My blog on  Extending Windows Azure BizTalk Services Using Message Inspectors, posted on AIS site,

Json, Send and Receive Pipelines for BizTalk Server.

Announcing the release of the Json pipelines for BizTalk Server, Rest (web-http) adapter was release in BT 2010 which opened up new playground for integration specialists, and we could boast of BizTalk server’s OOB support both Rest and Soap protocols, but the one thing that was still missing was Json support.

Here in the blog post I will discuss & demonstrate on how to add json support using custom pipeline components, the entire source code is available on GitHub including unit tests ,apart from BizTalk we need the ESB tool kit components installed (only the pipelines).

Scenario 1: We need to send out a Json Message to an external endpoint, one of the solution for this is to create a new PC and use the Newtonsoft Json libraries JsonConvert.SerializeObject method to convert the xml stream into an object and generate a json string, the following is the code and the pipeline implementation.

Xml to Json pipeline component (DotNetTypesToJsonConverter.cs)

Json send pipeline.

IBaseMessage IComponent.Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
Trace.WriteLine(“DotNetTypesToJsonConverter Pipeline – Entered Execute()”);
Trace.WriteLine(“DotNetTypesToJsonConverter Pipeline – TypeName is set to: ” + TypeName);
IBaseMessagePart bodyPart = pInMsg.BodyPart;
if (bodyPart != null)

{

Stream originalStream = bodyPart.GetOriginalDataStream();

if (originalStream != null)

{

Type myClassType = Type.GetType(TypeName);

object reqObj = PcHelper.FromXml(originalStream, myClassType);

string jsonText = JsonConvert.SerializeObject(reqObj, myClassType, Formatting.None,

new JsonSerializerSettings());

Trace.WriteLine(“DotNetTypesToJsonConverter output: ” + jsonText);

byte[] outBytes = Encoding.ASCII.GetBytes(jsonText);

var memStream = new MemoryStream();

memStream.Write(outBytes, 0, outBytes.Length);

memStream.Position = 0;

bodyPart.Data = memStream;

pContext.ResourceTracker.AddResource(memStream);

}

}

Trace.WriteLine(“DotNetTypesToJsonConverter Pipeline – Exited Execute()”);

return pInMsg;

}

Scenario 2: We need to receive a Json message from an external endpoint and convert it into Xml for BizTalk’s further processing, one of the solution for this is to create a new PC and use the Newtonsoft Json libraries , I used the idea from an existing blog post http://www.modhul.com/2013/04/30/restfully-getting-json-formatted-data-with-biztalk-2013/, to create an XML document with few minor enhancements, if a root node is specified, the new xml will be added as a child to it or else a new xml document will be created and the root node will be based on the json message, and as we know BizTalk needs a namespace so we use the ESB toolkit’s add namespace component to add new namespace to the Xml (more than one can be added) created in the previous stage and finally we use the XML disassembler component to inform BizTalk of the new xml document, the following is the code and the pipeline implementation.

Json to xml pipeline component

Json receive pipeline.

IBaseMessage IComponent.Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
string json;
Trace.WriteLine(“JsonToXmlConverter Pipeline – Entered Execute()”);
Trace.WriteLine(String.Format(“JsonToXmlConverter Pipeline – RootNode: {0}”, Rootnode));
var originalStream = pInMsg.BodyPart.GetOriginalDataStream();

using (TextReader reader = new StreamReader(originalStream))

{

json = reader.ReadToEnd();

}

Trace.WriteLine(String.Format(“JsonToXmlConverter Pipeline – Read JSON Data: {0}”, json));

Trace.WriteLine(String.Format(“JsonToXmlConverter Pipeline – Deserializing JSON to Xml…”));

try

{

// Append deserialized Xml data to master root node.

XmlDocument xmlDoc =!string.IsNullOrWhiteSpace(Rootnode) ? JsonConvert.DeserializeXmlNode(json, Rootnode) : JsonConvert.DeserializeXmlNode(json);

Trace.WriteLine(String.Format(“JsonToXmlConverter Pipeline – Xml: {0}”, xmlDoc.InnerXml));

var output = Encoding.ASCII.GetBytes(xmlDoc.InnerXml);

var memoryStream = new MemoryStream();

memoryStream.Write(output, 0, output.Length);

memoryStream.Position = 0;

pInMsg.BodyPart.Data = memoryStream;

}

catch (Exception ex)

{

Trace.WriteLine(String.Format(“JsonToXmlConverter Pipeline – Exception: {0}”, ex.Message));

}

pInMsg.BodyPart.Data.Position = 0;

return pInMsg;

}

The following video demo’s the end to end working solution:

BizTalk 2012 R2 and REST Example Walkthrough

The recent BizTalk 2012 R2 release has inbuilt REST support for both exposing, and consuming a REST service using the WebHttp binding

In this blog post I will provide a walkthrough on how to configure BizTalk to:

  1. Expose an Orchestration as REST service (POST).
  2. Consume a REST service (POST).

We will use the Hello World orchestration example that is part of the SDK.

  1. Expose an Orchestration as REST service (POST):
    1. Deploy the HelloWorld Orchestration sample and test to make sure everything works as expected
    2. Modify the receive port
      1. Modify the Transport type to use WCF-WebHttp and click to configure

      2. Update the url mapping to the following, the operation name string should be the same operation name used in the orchestration.

        <BtsHttpUrlMapping>

        <Operation Name=”Operation_1″ Method=”POST” Url=”/HelloWorld”/>

        </BtsHttpUrlMapping>



      3. Save and restart the orchestration and BizTalk Services.
      4. Launch Fiddler and submit a request to the url http://localhost/HelloWorld and you will see a new file created in the folder C:\Program Files (x86)\Microsoft BizTalk Server 2010 R2\SDK\Samples\Orchestrations\HelloWorld\Out (note: this is the default installation path).

  2. Consume a Rest service (POST)
    1. Create a new MVC app, with webapi controller and modify the the Post method of the ValuesController to the following to accept a generic HttpRequestMessage (or you could probably do an xsd.exe and import the generated cs file into the mvc project and add it as an parameter, this I will cover in the later posts).
      1. public
        void Post(HttpRequestMessage value)

    2. Modify the send port:
      1. Modify the transport to use Wcf-WebHttp binding and click on configure

      2. Update the url mapping to the following, the operation name string should be the same operation name used in the orchestration.

        <BtsHttpUrlMapping>

        <Operation Name=”Operation_1″ Method=”POST” Url=”/api/values/post”/>

        </BtsHttpUrlMapping>

      3. And in the post you could probably send it to another downstream service or write it to a file or something.
  3. In the upcoming posts I will show you on how to use other the other http verbs, use cases and add JSON support.

Order of map and pipeline execution in BizTalk ports

For future reference to all those that want to remember in what order maps and pipelines get executed on receive and send ports:

One-way Receive Port:

End system –> Receive Adapter –> Receive Pipeline –> Inbound Map –> Message Box

Request Response Receive Port:

End system –> Adapter –> Receive Pipeline –> Inbound Map -> Message Box -> Outbound Map –> Send Pipeline –> Adapter –> End System

One-way Send Port (static and dynamic):

Message Box –> Outbound Map –> Send Pipeline –> Send Adapter –> End System

Request Response Send Port (static and dynamic):

Message Box-> Outbound Map –> Send Pipeline –> Adapter -> End system –> Adapter –> Receive Pipeline –> Inbound Map -> Message Box

Using BizTalkCop for BizTalk 2010 and fxcop 10.0

i had to do a qucik code review of a biztalk project, as usual downloaded biztalk cop from code plex and reazlied that it will not work with vs 2010 professional.  fxcop 1.36 only supports versions less than .net framework 3.5 and the codeplex project has been not active for a long time, tried sending a mail to the contributor but it did not help

so downloaded fxcop 10.0 this seems to be the latest version and tried using this but i ended up with few issues, i downloaded the src code of biztalk cop modified the fxcop sdk and cci assemblies and droped it into the fxcop (10.0) rules folder and download the fxcop gui and now i have code analysis working as expected.

Hopefully they update BizTalk cop on codeplex to support biztalk 2010