Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Generating message with expressions
- This topic has 2 replies, 1 voice, and was last updated 8 years, 1 month ago by
community-content.
-
AuthorPosts
-
-
March 13, 2006 at 2:47 PM #13140
What can I do if I would like to create an empty message in Message Assignment? There are much documents on the Net about this subject, but I can’t use any of them.
Usually the messages come form ports, or I can create them with Transform Shapes. But how can I create a message from program code?
If I simply give a value to the message fileds, on build it says that I use an unconstructed message.
If I use the
msgEmpty=new System.Xml.XmlDocument();
expression, I can deploy and run the orchestration, but I get a long error message about distinguished fileds, and that: I must initialize the message part data.If I give values to the elements, for example:
msgEmpty.MessRow.First=\”There was an error\”;
I get the same error message.If I use the
msgEmpty.Parameters=null;
code, I get an exception.I tried to read from an xml file in the Message Assignment, but it didn’t work.
So, is there any way to create a new message from code?
It should not be too difficult, but I don’t know the correct method to do this. -
March 14, 2006 at 12:05 PM #13141
Thanks!
The first way seems to be good for me. But I had to insert the namespace to the <root> element also. Without it, the pipeline can’t process the xml.
Now, I will try to do it with a multi-part message also, but I think, it will work.
-
March 13, 2006 at 9:10 PM #13142
There is no way of creating a blank Xml document that would suit all implementations. So when constructing an Xml message you have to build it yourself.
When you create a new XmlDocument it is empty, it has no nodes .
There are a number of ways of constructing a blank XmlDocument.
1. Use an XmlDocument variable
[code:1:6548ce32bb]XmlDocVariable.LoadXml(\"<root><record><field/></record></root>\");
YouMessage = XmlDocVariable;[/code:1:6548ce32bb]2. Use a .NET serializable class
[code:1:6548ce32bb]using System;
using Microsoft.XLANGs.BaseTypes;namespace NetClass
{
[Serializable]
public class MsgClass
{
public MsgClass()
{
StrField = \"OK\";
IntField = 1;
}[DistinguishedFieldAttribute()]
public String StrField;[DistinguishedFieldAttribute()]
public int IntField;
}
}
[/code:1:6548ce32bb]
The in a message assignment shape
[code:1:6548ce32bb]message = new NetClass.MsgClass[/code:1:6548ce32bb]3. Use a .NET helper class
[code:1:6548ce32bb]
namespace CreateMsgHelperpublic class Helper
{
private static XmlDocument _template = null;
private static object _sync = new object();
private static String LOCATION = @\":\\MyTemplateLocation\\MyMsgTemplate.xml\";public static XmlDocument GetXmlDocumentTemplate()
{
XmlDocument doc = _template;
if (doc == null)
{
// Load the doc template from disk.
doc = new XmlDocument();
XmlTextReader reader = new XmlTextReader(LOCATION);
doc.Load(reader);// Synchronize assignment to _template.
lock (_sync)
{
XmlDocument doc2 = _template;
if (doc2 == null)
{
_template = doc;
}
else
{
// Another thread beat us to it.
doc = doc2;
}
}
}// Need to explicitly create a clone so that we are not
// referencing the same object statically held by this class.
doc = (XmlDocument) doc.CloneNode(true);
return doc;
}
}[/code:1:6548ce32bb]
The in a message assignment shape
[code:1:6548ce32bb]MsgOut = CreateMsgHelper.Helper.GetXmlDocumentTemplate();[/code:1:6548ce32bb]
3.Use a map with a Transform shape.
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.