【问题标题】:how to consume a web service in mule flow?如何在 mule 流中使用 Web 服务?
【发布时间】:2015-05-27 09:51:04
【问题描述】:

我从 Mule 流开始。我正在尝试在其中使用 Web 服务。 但是我在运行时遇到了一些错误。

XML 解析器报告的错误:prolog 中不允许内容

这是我的代码

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ws="http://www.mulesoft.org/schema/mule/ws" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8095" doc:name="HTTP Listener Configuration"/>
    <ws:consumer-config name="Web_Service_Consumer" wsdlLocation="MSCRMDiscoveryService_WSDL.wsdl" service="DiscoveryService" port="CustomBinding_IDiscoveryService" serviceAddress="https://disco.crm5.dynamics.com/XRMServices/2011/Discovery.svc" doc:name="Web Service Consumer"/>
    <data-mapper:config name="Xml_ExecuteResponse__To_Xml_Execute_" transformationGraphPath="xml_executeresponse__to_xml_execute_.grf" doc:name="Xml_ExecuteResponse__To_Xml_Execute_"/>
    <data-mapper:config name="Xml_ExecuteResponse__To_Xml_Execute__1" transformationGraphPath="xml_executeresponse__to_xml_execute__1.grf" doc:name="Xml_ExecuteResponse__To_Xml_Execute__1"/>
    <flow name="mscrmdiscoveryservice-consumerFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="*" doc:name="HTTP"/>
        <data-mapper:transform config-ref="Xml_ExecuteResponse__To_Xml_Execute_" doc:name="Xml&lt;ExecuteResponse&gt; To Xml&lt;Execute&gt;"/>
        <ws:consumer config-ref="Web_Service_Consumer" operation="Execute" doc:name="Web Service Consumer"/>
        <data-mapper:transform config-ref="Xml_ExecuteResponse__To_Xml_Execute__1" doc:name="Xml&lt;ExecuteResponse&gt; To Xml&lt;Execute&gt;"/>
    </flow>
</mule>

wsdl 文件

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="HelloWorldService" targetNamespace="http://example.org/">
  <wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://example.org/" elementFormDefault="unqualified" targetNamespace="http://example.org/" version="1.0">
<xs:element name="sayHi" type="tns:sayHi"/>
<xs:element name="sayHiResponse" type="tns:sayHiResponse"/>
<xs:complexType name="sayHi">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHiResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
  </wsdl:types>
  <wsdl:message name="sayHi">
    <wsdl:part element="tns:sayHi" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="sayHiResponse">
    <wsdl:part element="tns:sayHiResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="HelloWorld">
    <wsdl:operation name="sayHi">
      <wsdl:input message="tns:sayHi" name="sayHi">
    </wsdl:input>
      <wsdl:output message="tns:sayHiResponse" name="sayHiResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="HelloWorldServiceSoapBinding" type="tns:HelloWorld">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="sayHi">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="sayHi">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="sayHiResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="HelloWorldService">
    <wsdl:port binding="tns:HelloWorldServiceSoapBinding" name="HelloWorldPort">
      <soap:address location="http://localhost:8085/hello"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

我该如何解决这个错误?

【问题讨论】:

  • 整理问题以提高可读性。
  • 'Content is not allowed in prolog':表示 xml 结构中存在一些问题,而不是有效的 xml(可能在您提供的输入 xml 中或两者之间)。
  • 你在data-mapper transfos 做什么?从您共享的配置中无法判断。

标签: web-services soap cxf mule jax-ws


【解决方案1】:

从您共享的流程中,很难判断错误到底存在于何处……可能是您的 XML 结构错误。
也不清楚 Datamapper 在使用外部 Web 服务时的使用
从 Mule 流中使用现有 Web 服务的最简单方法是使用 set payload 或 XSLT 转换器为外部服务准备/构建 soap 请求,然后通过 HTTP 出站或 HTTP 请求组件调度它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 2017-03-07
    • 2016-04-01
    相关资源
    最近更新 更多