tags:

views:

830

answers:

2

Hi there,

Having a problem trying to create a function, as part of a BizTalk helper class that returns a value of type (Microsoft.XLANGs.BaseTypes.XLANGMessage). The function code is as follows:

public XLANGMessage UpdateXML (XLANGMessage inputFile)
{
   XmlDocument xDoc = new XmlDocument();
   XLANGMessage outputFile;
   xDoc = (System.Xml.XmlDocument) inputFile[0].RetrieveAs(typeof(System.Xml.XmlDocument));

   // Modify xDoc document code here

   outputFile[0].LoadFrom(xDoc.ToString());
   return outputFile;
}

This code does not build as I receive an error stating "Use of unassigned local variable 'outputFile'. I have tried to initialize the 'outputFile' using the new keyword ( = new ....), but that also results in a build error.

What am I doing wrong?

+1  A: 

In the code you have provided, change the line:

XLANGMessage outputFile;

to:

XLANGMessage outputFile = null;

and change the TypeOf to typeof

You might want to take a look at these two blog articles here and here that both mention some better ways of doing this including passing classes based on your xsd instead of the XLANGMessage, and using a stream instead of the XMLDocument.


After doing a quick once over with this (because I had a bad feeling) I'm not sure if BizTalk will consume the returned XLANGMessage the way you are trying. It fails with an unconstructed error when I try to use it in my test harness. Later tonight when I have some free time I'll see if there is an easy way to use the XLANGMessage directly in orchestration shapes. Add a comment if you manage to get it working before I update.

David Hall
A: 

There is no need to return XLangMessage in this case. You can return the XmlDocument object itself and assign it a new variable in a Construct Message Shape.

Also it's not a good idea to return XLangMessage from user code. See here http://msdn.microsoft.com/en-us/library/aa995576.aspx

HashName