如何在mule 3.7.0 CE上代理Web服务

时间:2015-07-28 21:32:31

标签: c# web-services proxy mule

我使用mule 3.4.0 CE来代理远程Web服务,但是使用新的3.7.0 CE我找不到任何关于流程的例子,所以我可以使用http共享连接器,任何线索?

对基于C#的消费者不起作用的示例:

<flow name="Test">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/services/teste/teste" doc:name="HTTP"/>
    <logger message="AutenticacaoServicoFlowTesteHttp - #[message]" level="INFO" doc:name="Logger"/>
    <response>
        <logger message="ATestHttp - response - #[message]" level="INFO" doc:name="Logger"/>
    </response>
    <set-variable variableName="queryStringIncompleto" value="#[message.inboundProperties.'host']/logTicket?ipFrom=#[message.inboundProperties.'http.remote.address']&amp;requestSize=#[message.inboundProperties.'http.request.uri'.length()]&amp;url=#[message.inboundProperties.'host']#[message.inboundProperties.'http.request.uri'.replaceAll(&quot;&amp;&quot;, &quot;%26&quot;)]&amp;userName=#[message.inboundProperties.'authorization']&amp;modifiedRequestSize=#[message.inboundProperties.'http.request.uri'.length()]" doc:name="QueryString LogTicket"/>
    <choice doc:name="Choice">
        <when expression="#[message.inboundProperties.'http.request.uri' == '/services/Autentic?wsdl']">
            <set-variable variableName="queryString" value="#[flowVars.queryStringIncompleto]&amp;method=#[message.inboundProperties.'http.method']" doc:name="QueryString LogBilhetagem"/>
            <cxf:proxy-service  namespace="logTeste.gov" service="AutenticacaoServico" payload="envelope" wsdlLocation="${targetServerLog}/servicos/v2/Autentic.svc?singleWsdl" soapVersion="1.2" doc:name="CXF"/>
        </when>
        <otherwise>
            <set-variable variableName="queryString" value="#[flowVars.queryStringIncompleto]&amp;method=#[message.inboundProperties.'SOAPAction'.replaceAll(&quot;\&quot;&quot;, &quot;&quot;)]" doc:name="QueryString LogTicket"/>
            <message-properties-transformer doc:name="Message Properties">
                <add-message-property key="SOAPAction" value="#[message.inboundProperties.'SOAPAction']"/>
            </message-properties-transformer>
            <outbound-endpoint exchange-pattern="request-response" address="${targetServerLog}/servicos/v2/Autentc.svc" encoding="UTF-8" mimeType="text/xml" doc:name="Generic"/>
        </otherwise>
    </choice>
    <set-variable variableName="payloadLog" value="#[message.payloadAs(java.lang.String)]" doc:name="Guarda Payload Log"/>
    <outbound-endpoint exchange-pattern="request-response" address="https://teste:teste@#[flowVars.queryString]" doc:name="Log Bilhetagem"/>
    <set-payload value="#[flowVars.payloadLog]" doc:name="Set Payload"/>
    <response>
        <message-properties-transformer doc:name="Message Properties">
            <add-message-property key="Content-Type" value="text/xml"/>
        </message-properties-transformer>
    </response>
</flow>

在大多数使用此WS的C#应用​​程序上都会执行第一次连接,而第二次连接会执行超时...

2 个答案:

答案 0 :(得分:2)

好的,发现问题并解决了,不是实现,我做的是将WS重定向到正确的位置,但我也将消息记录到另一个WS,这将挂起流程,将无法进行级联打电话给很多方法。 所以我只是取出了第二个出站来记录消息,我将使用另一种方法来记录消息。

代码:

<flow name="Test">
<http:listener config-ref="HTTP_Listener_Configuration" path="/services/teste/teste" doc:name="HTTP"/>
<set-variable variableName="queryStringIncompleto" value="#[message.inboundProperties.'host']/logTicket?ipFrom=#[message.inboundProperties.'http.remote.address']&amp;requestSize=#[message.inboundProperties.'http.request.uri'.length()]&amp;url=#[message.inboundProperties.'host']#[message.inboundProperties.'http.request.uri'.replaceAll(&quot;&amp;&quot;, &quot;%26&quot;)]&amp;userName=#[message.inboundProperties.'authorization']&amp;modifiedRequestSize=#[message.inboundProperties.'http.request.uri'.length()]" doc:name="QueryString LogTicket"/>
<choice doc:name="Choice">
    <when expression="#[message.inboundProperties.'http.request.uri' == '/services/Autentic?wsdl']">
        <set-variable variableName="queryString" value="#[flowVars.queryStringIncompleto]&amp;method=#[message.inboundProperties.'http.method']" doc:name="QueryString LogBilhetagem"/>
        <cxf:proxy-service  namespace="logTeste.gov" service="AutenticacaoServico" payload="envelope" wsdlLocation="${targetServerLog}/servicos/v2/Autentic.svc?singleWsdl" soapVersion="1.2" doc:name="CXF"/>
    </when>
    <otherwise>
        <set-variable variableName="queryString" value="#[flowVars.queryStringIncompleto]&amp;method=#[message.inboundProperties.'SOAPAction'.replaceAll(&quot;\&quot;&quot;, &quot;&quot;)]" doc:name="QueryString LogTicket"/>
        <message-properties-transformer doc:name="Message Properties">
            <add-message-property key="SOAPAction" value="#[message.inboundProperties.'SOAPAction']"/>
        </message-properties-transformer>
        <outbound-endpoint exchange-pattern="request-response" address="${targetServerLog}/servicos/v2/Autentc.svc" encoding="UTF-8" mimeType="text/xml" doc:name="Generic"/>
    </otherwise>
</choice>
<response>
    <message-properties-transformer doc:name="Message Properties">
        <add-message-property key="Content-Type" value="text/xml"/>
    </message-properties-transformer>
</response>

答案 1 :(得分:1)

您尝试代理服务的方式不是理想的做法,也不是3.4中的理想选择,请参阅以下文档页面:

https://developer.mulesoft.com/docs/display/current/Proxying+Web+Services+with+CXF https://developer.mulesoft.com/docs/display/current/Web+Service+Proxy+Pattern

这是代理网络服务的两种标准方式。