BizTalk Server 2004 : B2B, EAI and .NET

Wednesday, September 29, 2004

Non-Uniform Sequential Convoys in BTS 2004 using Correlation

This is another primer on Sequential Convoys, but non-uniform ones this time. With a uniform Sequential Convoy, correlated messages have to be of the same type. But there might be situations where we would want to implement Sequential Convoys with different messages. The sample below illusatrates this concept by taking 2 messages of different types, and merging them to produce 1 output message. The input messages are correlated into a single orchestration instance by a promoted property called "Primary".


Non-Uniform Sequential Convoy


Most information in my previous post about Uniform Sequential Convoys holds true in this case too.

You can get the source files here

Post a comment if you need any clarifications.


View complete post...

Monday, September 27, 2004

Using XmlSerializer in the BizTalk Web Service Proxy.

This is something that most people will be aware of but might be helpful for newbies. The BizTalk Web Services Publishing Wizard, creates new datatypes for input and output messages during creation of the Web Service that exposes Orch/Schemas. Adding a web reference to this web service will generate the same datatypes, whose definitions can be found in the Reference.cs file. If the external system already generates XML, creating the input message object can be a drag.
A quick way of creating the input message objects from XML and converting the output message objects to XML, is by using the XML Serializer class. Here's the sample code.

//creating a new RequestMsg
objectRequestMsg objRequestMsg = new RequestMsg();

//Create an XML Serializer for RequestMsg document
XmlSerializer serRequestMsg = new XmlSerializer(objRequestMsg.GetType(), "http://schemas.devdutt.com/XMLSchema/v1/InputMsg.xsd");

//Deserializing XML into RequestMsg class
//strRequestMsgXml is the XML String
objRequestMsg = (RequestMsg)(serRequestMsg.Deserialize(new XmlTextReader(new StringReader(strRequestMsgXml))));

//Call RequestMsg Web Service and send the Request
//orchInvoker is the Web Service Proxy Object
//Submit is the Web Method
object obj = (orchInvoker.Submit(objRequestMsg));

//Create an XML Serializer for OutputMsg document
XmlSerializer serResponseMsg = new XmlSerializer(obj.GetType(), "http://schemas.devdutt.com/XMLSchema/v1/OutputMsg.xsd");

//Create a temporary memory object for storing xml stream
MemoryStream ms = new MemoryStream();

//Serialize the output document
serResponseMsg.Serialize(ms, obj);

//Convert the memory stream into the string buffer
string strResponseMsgXml = System.Text.Encoding.ASCII.GetString(ms.GetBuffer());

Any questions, post a comment.



View complete post...

Saturday, September 18, 2004

Using recursion in the In-line XSLT Template type Scripting Functoid

People using In-Line XSLT Templates in their scripting functoids often run into the need for looping, WITHOUT using an <xsl:for-each>. An example in the BizTalk context would be, if you had a comma separated string in the source schema and wanted to tokenize it into multiple destination schema elements. The following XSLT template does that for you.

<xsl:template name="TokenizeCommaSepString">
<xsl:param name="stringToTokenize" />
<xsl:param name="destinationElementName" />

<xsl:if test="$stringToTokenize != ''">
<xsl:choose>
<xsl:when test="contains($stringToTokenize, ',')=0">
<xsl:element name="{$destinationElementName}">
<xsl:value-of select="$stringToTokenize" />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{$destinationElementName}">
<xsl:value-of select="substring-before($stringToTokenize, ',')" />
</xsl:element>
</xsl:otherwise>
</xsl:choose>

<xsl:call-template name="TokenizeCommaSepString">
<xsl:with-param name="stringToTokenize" select="substring-after($stringToTokenize,',')" />
<xsl:with-param name="destinationElementName" select="$destinationElementName" />
</xsl:call-template>

</xsl:if>
</xsl:template>

Drag a Scripting functoid onto the BizTalk Mapper. Go to properties and choose Configure functoid script. Choose Inline XSLT Call Template as the Script Type. Paste the above code in the Script Buffer text area. This functoid will take the comma separated string in as the first parameter and the destination element name as the second parameter. It will split the string into parts and create a sequence of elements in the destination message.

Observe the use of recursion (marked in bold), to solve similar problems. Have any questions, post a comment.



View complete post...