我们希望使用 SOAP 代理 RESTful Web 服务。
REST 服务使用 GET 方法并通过查询参数接受输入。它生成 application/csv 类型的资源。
WSO2 ESB/Synapse 是否支持这种场景,是否有可用的示例?
请求示例
SOAP 代理请求:
<request>
<fromDate>2012-01-01</fromDate>
<toDate>2012-12-31</toDate>
</request>
REST 端点请求:
http://localhost/person?fromDate=2012-01-01&toDate=2012-12-31
响应示例
REST 端点响应
"Name","Age","Sex"
"Geoff","22","Male"
SOAP 代理响应
<person>
<name>Geoff</name>
<age>22</age>
<sex>Male</sex>
<person>
非常感谢。
最佳答案
如果我理解正确的话,您希望将 REST 服务公开为 SOAP 服务,以便 SOAP 客户端可以通过 ESB 访问您的 REST 服务?
如果是这种情况,则有可能:) 您应该从以下位置查看样本 152:http://docs.wso2.org/wiki/display/ESB451/Proxy+Service+Samples
它将解释如何获取 SOAP 请求并将其传递到 REST 后端,然后将 REST 响应转换为 SOAP 响应。
编辑:这是一个关于如何执行您在评论中提出的要求的示例配置,希望它能帮助您开始:)
<proxy xmlns="http://ws.apache.org/ns/synapse" name="RESTProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<!-- We set the HTTP Method we want to use to make the REST request here -->
<property name="HTTP_METHOD" value="GET" scope="axis2"/>
<!-- This is where the magic happens, for what you want i.e. mapping SOAP "params" to REST query param's -->
<property name="messageType" value="application/x-www-form-urlencoded" scope="axis2"/>
<send>
<endpoint>
<!-- This is the RESTful URL we are going to query, like the one in the ESB example 152 -->
<address uri="http://localhost/person" />
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<property name="messageType" value="text/xml" scope="axis2"/>
<send/>
</outSequence>
</target>
<description></description>
</proxy>
那么您向 ESB 发出的 SOAP 请求应该类似于:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<person>
<fromDate>2012-01-01</fromDate>
<toDate>2012-12-31</toDate>
</person>
</soapenv:Body>
</soapenv:Envelope>
希望有帮助:)
关于rest - 使用 SOAP 和 WSO2 ESB 代理 RESTful 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13987882/