【问题标题】:Returning a value of type Microsoft.XLANGs.BaseTypes.XLANGMessage返回 Microsoft.XLANGs.BaseTypes.XLANGMessage 类型的值
【发布时间】:2008-11-03 00:41:07
【问题描述】:

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

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”,但这也会导致构建错误。

我做错了什么?

【问题讨论】:

    标签: c# .net xml biztalk


    【解决方案1】:

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

    XLANGMessage outputFile;
    

    到:

    XLANGMessage outputFile = null;
    

    并将TypeOf 更改为typeof

    您可能想看看这两篇博客文章 herehere,它们都提到了一些更好的方法,包括基于您的 xsd 而不是 XLANGMessage 传递类,以及使用流而不是XMLDocument.


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

    【讨论】:

      【解决方案2】:

      在这种情况下不需要返回 XLangMessage。您可以返回 XmlDocument 对象本身并在 Construct Message Shape 中为其分配一个新变量。

      此外,从用户代码返回 XLangMessage 也不是一个好主意。 看这里http://msdn.microsoft.com/en-us/library/aa995576.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-06
        • 1970-01-01
        • 1970-01-01
        • 2022-08-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多