如何在 Mule Flow 中使用 SOAP Web 服务?

2024-01-08

我从 Mule 流程开始,并且已经看到了我已经看到了此页面http://www.mulesoft.org/documentation/display/MULE3CONCEPTS/Using+Mule+with+Web+Services http://www.mulesoft.org/documentation/display/MULE3CONCEPTS/Using+Mule+with+Web+Services and http://www.mulesoft.org/documentation/display/MULEWS/Consuming+SOAP+Web+Services+in+Mule http://www.mulesoft.org/documentation/display/MULEWS/Consuming+SOAP+Web+Services+in+Mule这个也有。他们没有多大帮助。目前,我有一个简单的骡子流程,如下所示。

流程定义

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

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.2.1"
    xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
    <flow name="EchoFlow" doc:name="EchoFlow">
        <http:inbound-endpoint exchange-pattern="request-response"
            host="localhost" port="8081" path="service/echoflow" doc:name="HTTP" />
        <cxf:jaxws-client operation="" serviceClass="com.myapp.demo.ServiceAImplService" 
            doc:name="SOAP"/>
        <outbound-endpoint address="http://localhost:8080/ServiceA/services/" doc:name="Generic"/>
    </flow>
</mule>

我正在使用 Mule 工作室。有一个 HTTP 入站端点需要响应。我尝试配置一个 jax-ws 客户端,它将调用实际的 Web 服务。该服务的 WSDL 是:

wsdl 文件

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="ServiceAImplService" targetNamespace="http://service.demo.myapp.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.demo.myapp.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.demo.myapp.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<import namespace="http://service.demo.myapp.com/" schemaLocation="http://localhost:8080/ServiceA/services/ServiceAImplPort?xsd=serviceaimpl_schema1.xsd"/>
</schema>
  </wsdl:types>
  <wsdl:message name="helloResponse">
    <wsdl:part element="tns:helloResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="hello">
    <wsdl:part element="tns:hello" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="IServiceA">
    <wsdl:operation name="hello">
      <wsdl:input message="tns:hello" name="hello">
    </wsdl:input>
      <wsdl:output message="tns:helloResponse" name="helloResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="ServiceAImplServiceSoapBinding" type="tns:IServiceA">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="hello">
      <soap:operation soapAction="urn:Hello" style="document"/>
      <wsdl:input name="hello">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="helloResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="ServiceAImplService">
    <wsdl:port binding="tns:ServiceAImplServiceSoapBinding" name="ServiceAImplPort">
      <soap:address location="http://localhost:8080/ServiceA/services/ServiceAImplPort"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

如您所见,我不太确定如何配置 jax-ws 客户端。那么,我到底如何在此流程中使用 SOAP Web 服务呢?


我的第二个问题:如何转换有效负载以从一个 Web 服务调用另一个 Web 服务(均为 SOAP)。流量会怎样?


最后,如何合并有效负载?假设我并行调用了三个 Web 服务,并且它们的响应全部返回。如何合并有效负载,以便可以在另一个服务中读取它(在组合并行调用的多个服务的响应之后)?



什么是等效的实现

       <pattern:web-service-proxy name="ex-proxy"
        inboundAddress="http://localhost:8081/xxx"
        outboundAddress="http://xx.xx.com/XXX_WS/xxxWService.asmx" /> 

使用 CXF 代理服务/客户端?这让我想到了另一个问题,何时使用 CXF 服务以及何时使用 CXF 客户端?最后,是否有 Mule Flow Orchestration 的详细文档或示例/教程?


尝试使用 CXF 代理(服务和客户端)。在这种情况下,您会将原始 XML 添加到流程中。当然,如果需要,您可以将其反序列化为 java,例如通过 XML 到对象转换器 (XStream)。

http://www.mulesoft.org/documentation/display/MULE3USER/Proxying+Web+Services+with+CXF http://www.mulesoft.org/documentation/display/MULE3USER/Proxying+Web+Services+with+CXF

从这里开始,有几种方法可以在中间转换有效负载。要么通过 java(如上所述)并转换 java 层对象,要么编写一个 XSLT 表来进行转换。或者使用 Java 和/或 Mule 提供的其他工具(脚本、xpath 等)转换 XML。

您可能想再次详细解释聚合案例。您是否想要合并响应以供将来使用,或者进行一个 Web 服务调用 -> 扇出 -> 聚合 -> 响应?

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Mule Flow 中使用 SOAP Web 服务? 的相关文章

随机推荐