MuleSoft DataWeave - 通过 Web 服务消费者调用 .NET SOAP 服务

MuleSoft DataWeave - Call .NET SOAP service via Web Service Consumer

我有一个 .NET Web 服务,它有一个接受字符串的方法。在 Mulesoft 的 Anypoint 工作室中,我已经成功构建了一个流程,它接受 POST,将 POSTed 字符串传递到服务中,并 returns 一个操作结果。

我现在正在尝试为类似服务创建流,不同之处在于该服务接受自定义对象,而不是字符串。当我使用 SOAP UI 直接测试我的服务时,我传入以下 XML 并且它在我的服务中成功构建了对象并且 MyFirstString 和 MySecondString 值可用于该服务。

肥皂 UI XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:pra="http://schemas.datacontract.org/2004/07/Pra.Lib.Transformation">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:Transform>         
         <tem:transformationData>            
            <pra:MyFirstString>test1</pra:MyFirstString>
            <pra:MySecondString>test2</pra:MySecondString>
         </tem:transformationData>
      </tem:Transform>
   </soapenv:Body>
</soapenv:Envelope>

但是,当我使用我的 Mule 流并将 DataWeave 放到我的 Web 服务消费者面前时,它会自动构建一个不适用于该服务的 XML 字符串。当我将调试器附加到服务时,它显示对象未 built/mapped 成功...调用 Web 服务消费者后,MyFirstString 和 MySecondString 为空。

DataWeave 代码:

%dw 1.0
%output application/xml
%namespace ns0 http://tempuri.org/
---
//Some output fields where skipped as the structure is too deep (more than 2 levels).
//To add missing fields click on the scaffold icon (second on the toolbar).
{
    ns0#Transform: {
        ns0#transformationData: {
            Xml: "test1",
            Xslt: "test2"
        }
    }
}

DataWeave 输出:

<?xml version='1.0' encoding='windows-1252'?>
<ns0:Transform xmlns:ns0="http://tempuri.org/">
  <ns0:transformationData>
    <Xml>test1</Xml>
    <Xslt>test2</Xslt>
  </ns0:transformationData>
</ns0:Transform>

返回的错误信息是"Error in deserializing body of request message for operation 'Transform'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'Transform' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'EXTRACT_DETAIL' and namespace ''. Message payload is of type: ElementNSImpl"

所以如果我理解这个错误......我的问题是我如何编码 DataWeave 以 SOAP UI 使用的 soap 信封格式输出......因为看起来元素结构 DataWeave 生成是什么给我带来了问题?非常感谢。

一位开发人员能够为我指明正确的方向。在 AnyPoint Studio 中,在 DataWeave/TransformMessage 组件的属性选项卡上,我必须单击“脚手架输出结构”按钮。这生成了以下输出(语法更改在下面以粗体显示)。我最初的印象是,当第一次将组件放入流中时,所有脚手架都是自动的。

更改的语法:

                ns1#Xml: "test1",
                ns1#Xslt: "test2"

整个脚手架:

%dw 1.0
%output application/xml
%namespace ns0 http://tempuri.org/
---
//Some output fields where skipped as the structure is too deep (more than 2 levels).
//To add missing fields click on the scaffold icon (second on the toolbar).
{
    ns0#Transform: {
        ns0#transformationData: {
            ns1#Xml: "test1",
            ns1#Xslt: "test2"
        }
    }
}

单击此处获取脚手架按钮 screen capture

是的,在配置您的 WSDL 之后,您可以拖放 Data Weave,然后单击脚手架,它会为您生成合适的结构。