【问题标题】:mule webservice consumer XML result issuemule web 服务使用 XML 结果问题
【发布时间】:2016-11-03 10:52:53
【问题描述】:

我从 ws:consumer 和 mulexml:xml-to-dom-transformer 获得了转义的 XML 结果,但我不知道如何通过 mule 组件对其进行转义,或者我做错了什么? 这是相关流程:

<ws:consumer config-ref="Web_Service_Consumer" operation="Login" doc:name="Web Service Consumer"/>
    <mulexml:xml-to-dom-transformer doc:name="XML to DOM" returnClass="java.lang.String"/>

我的结果:

........&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;LoginResponse xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; ..........

我该怎么办?

我使用 mule anypoint studio 6.1.2

更新:

基于https://docs.mulesoft.com/mule-user-guide/v/3.6/web-service-consumer 我在ws:consumer 之前和之后使用dw:transform-message 并使用DataSense 映射输入和输出结果

<dw:transform-message metadata:id="92383237-87b0-42ed-b794-b8f247cc3af5" doc:name="Transform Message">
            <dw:input-payload mimeType="application/csv"/>
            <dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://tempuri.org/
---
{
    ns0#Login: {
        ns0#Username: payload.Username,
        ns0#Password: payload.pass
    }
}]]></dw:set-payload>
        </dw:transform-message>
        <ws:consumer config-ref="Web_Service_Consumer" operation="Login" doc:name="Web Service Consumer"/>
        <dw:transform-message metadata:id="39ba326e-a6f4-4e3f-8de9-b42ddc0f19b2" doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://tempuri.org/
%namespace ns1 http://www.w3.org/2001/XMLSchema
%namespace ns2 http://www.w3.org/XML/1998/namespace
---
{
    ns0#LoginResponse: {
        ns0#LoginResult: {
            ns1#schema @(targetNamespace: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@targetNamespace , version: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@version , finalDefault: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@finalDefault , blockDefault: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@blockDefault , attributeFormDefault: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@attributeFormDefault ,
            elementFormDefault: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@elementFormDefault , id: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@id , lang: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@ns2#lang): {
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#notation map ((notation , indexOfNotation) -> {
                    ns1#notation: {
                    }
                })),
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#attribute map ((attribute , indexOfAttribute) -> {
                    ns1#attribute: {
                    }
                })),
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#element map ((element , indexOfElement) -> {
                    ns1#element: {
                    }
                })),
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#attributeGroup map ((attributeGroup , indexOfAttributeGroup) -> {
                    ns1#attributeGroup: {
                    }
                })),
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#group map ((group , indexOfGroup) -> {
                    ns1#group: {
                    }
                })),
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#complexType map ((complexType , indexOfComplexType) -> {
                    ns1#complexType: {
                    }
                })),
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#simpleType map ((simpleType , indexOfSimpleType) -> {
                    ns1#simpleType: {
                    }
                })),
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#annotation map ((annotation , indexOfAnnotation) -> {
                    ns1#annotation: {
                    }
                })),
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#redefine map ((redefine , indexOfRedefine) -> {
                    ns1#redefine: {
                    }
                })),
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#import map ((import , indexOfImport) -> {
                    ns1#import: {
                    }
                })),
                (payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#include map ((include , indexOfInclude) -> {
                    ns1#include @(id: include.@id , schemaLocation: include.@schemaLocation): {
                        ns1#annotation: include.ns1#annotation
                    }
                }))
            }
        }
    }
}]]></dw:set-payload>
        </dw:transform-message>

但是出现了这个错误:

    Root Exception stack trace:
javax.xml.stream.XMLStreamException: Trying to bind URI http://www.w3.org/XML/1998/namespace to prefix "{0}" (can only bind to xml)

【问题讨论】:

  • 尝试在&lt;ws:consumer/&gt;之后放置&lt;mulexml:dom-to-xml-transformer doc:name="DOM to XML"/&gt;而不是&lt;mulexml:xml-to-dom-transformer doc:name="XML to DOM"/&gt;转换器
  • 我这样做了,但出现了相同的结果

标签: xml web-services mule anypoint-studio


【解决方案1】:

据我了解,转换 web 服务结果是基于您的要求,这不是必需的步骤。消费后真的需要变压器吗?尝试在消费者之后移除变压器并查看解决问题。也尝试在消费者之后使用和不使用变压器进行调试并验证结果。 对于 xml 转义字符问题,我在 mule exchange (https://www.mulesoft.com/exchange#!/global-global-weather-wsdl?types=WSDL) 上尝试了 SOAP webservice,并得到了与转义字符相似的结果,但原因是 webservice 响应(但即使您的结果在 xml 声明中有转义字符,您的结果看起来也不同以及)来自带有转义字符的数据库,可能骡子不是原因。我在 webservicex.net (http://webservicex.net/New/Home/ServiceDetail/23) 上尝试了不同的服务,它运行良好,没有任何问题。

【讨论】:

    猜你喜欢
    • 2015-12-19
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多