尝试创建函数时遇到问题,作为返回类型值(Microsoft.XLANGs.BaseTypes.XLANGMessage)的BizTalk帮助程序类的一部分。功能代码如下:

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;
}

此代码未构建,因为我收到一条错误,指出“使用未分配的局部变量” '输出文件'。我试图使用new关键字(= new ....)初始化'outputFile',但这也会导致构建错误。

我做错了什么?

有帮助吗?

解决方案

在您提供的代码中,更改行:

XLANGMessage outputFile;

为:

XLANGMessage outputFile = null;

并将 TypeOf 更改为 typeof

您可能需要查看这两篇博客文章此处此处两者都提到了一些更好的方法,包括基于xsd而不是XLANGMessage传递类,以及使用流而不是 XMLDocument


快速完成一次(因为我有一种不好的感觉)我不确定BizTalk是否会按照您尝试的方式使用返回的 XLANGMessage 。当我尝试在我的测试工具中使用它时,它会因未构造的错误而失败。今晚晚些时候,当我有空闲时间时,我会看到是否有一种简单的方法可以直接在编排形状中使用 XLANGMessage 。如果您在我更新之前设法让它正常工作,请添加评论。

其他提示

在这种情况下,无需返回XLangMessage。您可以返回XmlDocument对象本身,并在Construct Message Shape中为其指定一个新变量。

从用户代码返回XLangMessage也不是一个好主意。 请参阅此处 http://msdn.microsoft.com/en-us/library/ aa995576.aspx

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top