2016-07-27 65 views
0

我想在ESB上公開一個將請求傳遞給SOAP服務的API(REST)。WSO2 ESB - Api到Soap的轉換

我的API是definined這樣:

<api xmlns="http://ws.apache.org/ns/synapse" name="__test" context="/mytest"> 

    <resource methods="GET" uri-template="/{symbol}"> 
     <inSequence> 

     <property name="symbol" expression="get-property('uri.var.symbol')"/> 

     <payloadFactory media-type="xml"> 
      <format> 
       <ser:getQuote xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd"> 
       <ser:request> 
         <xsd:symbol>$1</xsd:symbol> 
       </ser:request> 
      </ser:getQuote> 

      </format> 
      <args> 
       <arg evaluator="xml" expression="get-property('symbol')"/> 
      </args> 
     </payloadFactory> 

     <log level="full"/> 

     <send> 
      <endpoint> 
       <wsdl service="SimpleStockQuoteService" port="SimpleStockQuoteServiceHttpEndpoint" 
        uri="http://localhost:9000/services/SimpleStockQuoteService?wsdl"/> 
      </endpoint> 
     </send> 
     </inSequence> 
    </resource> 
</api> 

但是,當我調用與HTTP網址://:8280/mytest,這時/ WSO2我HEVE在控制檯上此錯誤

<soapenv:Reason xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"> 
<soapenv:Text xml:lang="en-US"> 
The endpoint reference (EPR) for the Operation not found is /services/SimpleStockQuoteService.SimpleStockQuoteServiceHttpEndpoint/WSO2?request= and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator. 
</soapenv:Text> 
</soapenv:Reason> 

因爲esb將請求的一部分追加到URL中。

我該如何解決這個問題? 謝謝

回答

1

你可以按照this指南來實現這一點。請注意,soap動作頭應按以下方式添加,並且端點不同。 <header name="Action" value="urn:getQuote"/>
在下面找到完整的解決方案API,

<api xmlns="http://ws.apache.org/ns/synapse" name="__test" context="/mytest"><resource methods="GET" uri-template="/{symbol}"> 
    <inSequence> 
    <property name="symbol" expression="get-property('uri.var.symbol')"/> 
    <payloadFactory media-type="xml"> 
     <format> 
      <ser:getQuote xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd"> 
       <ser:request> 
       <xsd:symbol>$1</xsd:symbol> 
       </ser:request> 
      </ser:getQuote> 
     </format> 
     <args> 
      <arg evaluator="xml" expression="get-property('symbol')"/> 
     </args> 
    </payloadFactory> 
    <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/> 
    <log level="full"/> 
    <header name="Action" value="urn:getQuote"/> 
    <send> 
     <endpoint> 
      <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/> 
     </endpoint> 
    </send> 
    </inSequence></resource></api> 

如果您想直接使用WSDL的網址,就可以實現這一目標用WSO2 API Manager,它可以在WSO2 API Cloud輕易嘗試。有一個類似的問題here