Saturday, May 30, 2009
BizTalk: Message Assignment shape. Assign value from one Schema to another Schema.
We can assign one schema to another by many ways. But best way to assign values to one schema from another schema is to use the Message assignment Shape inside the Message Construct shape. Let’s take an example for it.
Example: Conversion of BillingAddress to ShippingAddress. For this I have two Schemas BillingAddress.xsd and ShippingAddress.xsd. All the elements of both schemas are promoted to Distinguished Fields, so that we can access them in message assignment shape. Both schemas are as follows:
Now I have created an orchestration, in which I am assigning the values of BillingAddress.xsd to ShippingAddress.xsd. For this I have created two messages msgBillingAddress and msgShippingAddress of BillingAddress.xsd and ShippingAddress.xsd types respectively. I have created a variable named varXmlDoc of System.Xml.XmlDocument type. My orchestration will look like the follows:
You can see in the image that there I have added a Receive Shape which will accept the msgBillingAddress and at the last you can see that I have added a Send Shape to send the ShippingAddress using msgShippingAddress. Between these two shapes(Receive & Send Shape), I have added a shape through which I am assigning values of BillingAddress to ShippingAddress message. And for this I have added a Construct shape and inside it I have added a Message Assignment Shape.
Now the purpose of this article is to share how to assign one message to another one. I have added the following code to assign BillingAddress to ShippingAddress message.
//Create a new object of XMLDocument. For this we will use the Variable created as XMLDocument.
varXmlDoc = new System.Xml.XmlDocument();
//We need to Load the variable with dummy XML.
//It can be same as generated instance.
//Note here we have to assign that instance that we need in target, not the //source schema.