
Constructing an XLANGMessage
When constructing an XLANGMessage with a stream, the stream type must either implement IStreamFactory or be a MemoryStream. The following code sample shows how to construct an XLANGMessage:
public class FileStreamFactory : IStreamFactory
{
string _fname;
public FileStreamFactory(string fname)
{
_fname = fname;
}
public Stream CreateStream()
{
return new FileStream
(
_fname,
FileMode.Open,
FileAccess.Read,
FileShare.Read
);
}
}
public static void AssignStreamFactoryToPart(XLANGMessage msg)
{
IStreamFactory sf = new FileStreamFactory( @”c:\data.xml” );
msg[0].LoadFrom( sf );
}
There may be times when you want to create a new message without transforming a source message. You can do this by using a variable of type System.Xml.XmlDocument and loading or otherwise constructing appropriate content. In the following example, XML is loaded from a string by using the LoadXml method of XmlDocument:
XmlVariable.LoadXml("<ns0:Root PONumber=\"047745351122111\" xmlns:ns0=\"http://BTSHTTPSend.SimpleSchema\"><MyChildRecord SubAttr1=\"Simple Attribute \" /></ns0:Root>");
XLANGMessage XmlMsg = XmlVariable;
The following example loads XML from a file by using the Load method of XmlDocument:
XmlVariable.Load("C:\MyData.xml");
XLANGMessage XmlMsg = XmlVariable;
Note |
|---|
|
If you want to construct larger messages, use one of the streaming methods demonstrated in the previous section or consider using the Transform shape in Orchestration Designer.
|