BizTalk: Pass an XLANG message or an XLANG message part to a .Net method call as a parameter in Orchestration. / Call .Net assembly to update the XLangMessage from Orchestration.

Today, I go through a solution to send XLangMessage to .net assembly from an Orchestration and update it. After update I need it in my Orchestration. For this I have created a project which I think it can help others.

I have created an Orchestration project named “CallNetAssemblyBySendingXLangMessageAndUpdate”. I have added the following simple schema in this project named “Book.xsd”.

Then I have created added an orchestration named “CallAssemblyXLangMessage.odx” in project. In this orchestration I am receiving the Book.xsd type message in receive shape. After this I have added the message assignment shape in the transform shape to update the values of message received of Book.xsd type. In this Construct shape I am creating a new message of Book.xsd type. In this message assignment shape I am calling the .net assembly in which I am updating the message.

I am sending the message in .Net assembly method as XLANGMessage parameter. Before going further I want to explain how I am accepting the message and updating it and return it.

For this I have added a new Class Library Project named “UpdateXLangMessage” in the Solution.

You need to create the Book class of Book.xsd created in Orchestration project by using XSD.exe util. You can create this class by using the following command at Visual Studio Command Prompt:

xsd.exe /c Book.xsd

This will create a Book.cs class. Add this project in class library project UpdateXLangMessage.

Now to receive XLangMessage and update it I have added the following class in this project.

========================================================

using System;
using Microsoft.XLANGs.BaseTypes;
namespace UpdateXLangMessage
{
public class UpdateMessage
{
public static Book UpdateBookMessage(XLANGMessage xlngMsg)
{
//Serialize message into Book Object
Book objBook = (Book)xlngMsg[0].RetrieveAs(typeof(Book));
try
{
//Update Book Object
objBook.Author = “Vijay Modi”
objBook.BookID = “00001”
objBook.BookName = “Biztalk 2006 R2”
objBook.Price = “Free”
objBook.Publisher = “Testing Publisher”
}
catch (XLANGsException xlngEx)
{
throw xlngEx;
}
catch (Exception ex)
{
throw ex;
}
//return book object
return objBook;
}
}
}

=========================================================

Build this class. Assign a Strong Name key to this project and add it in GAC using following command in Visual Studio Command Prompt.

gacutil /i UpdateXLangMessage.dll

Now we are going back to our Orchestration project. In Orchestration project add the reference of the .Net class library project.

Now in our Orchestration’s message assignment shape write the following expression:

//msgBookNew is the new message created of Book.xsd schema type

//msgBook is the message received in receive shape

msgBookNew = UpdateXLangMessage.UpdateMessage.UpdateBookMessage(msgBook);

Add the send shape just below the Transform shape in the orchestration. Assign the msgBookNew message in this send shape. The orchestration will look like as below:

Now deploy your orchestration project and test it. Some important reference I have found on the net are as below:

Reference:
http://support.microsoft.com/kb/917841
http://msdn.microsoft.com/en-us/library/aa995576.aspx

You can write your comments here:)

Regards,
Vijay Modi

Advertisements

About Vijay Modi

Having 12+ years of experience in web application development. Expertise in various domains like E-Commerce, E-Learning, Insurance. I have expertise in web application development, window application development, Performance improvement, bug fixing etc. I am believing in quality work and achieving deadlines. Also like to work on new technologies and quick learner.
This entry was posted in BizTalk Server and tagged , . Bookmark the permalink.

6 Responses to BizTalk: Pass an XLANG message or an XLANG message part to a .Net method call as a parameter in Orchestration. / Call .Net assembly to update the XLangMessage from Orchestration.

  1. adam gump says:

    This probably only applies to small messages, I assume it cost the same memory footprint with XmlDocument.

  2. Vijay Modi says:

    Adam,

    Yor are right. But I forget to write the Finally block in .Net code. In finaly block we can destroy the message ‘xlngMsg’. I think it will not eat up the memory.

  3. aroder says:

    Vijay,

    Have you run into the “Unknown XML attribute” error? There are a couple of xmlns attributes inserted into the root node.

  4. Vijay Modi says:

    Aroder,

    Where are you facing this error?

    Regards,
    Vijay Modi

  5. ashok says:

    hi i have a multiple Message Type is 1)Request Schema ,2)Acknowledgement Schema and 3)Reject Schema these Schema types…my Actival schemas is diffrent types like..

    Submit Order is SearchOrderSend.xsd,SearchOrderSendAcknowledge.xsd and SearchOrderSendReject.xsd

    Query Search Order is
    QuerySearchOrderSend.xsd,QuerySearchOrderSendAcknowledge.xsd and QuerySearchOrderSendReject.xsd

    please give me a best example in step wise….i never forgot in my life u..plz..

  6. Virendra Chothe says:

    Hi Vijay,
    This article is useful.However how to update the XLANG unbounded message.
    for e.g i have structure like below:

    .
    .
    .

    </

    I have to update the every attributr value of RecFileName.

    So how to the function for that as you mentioned above.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s