WSO2:基于方法参数的SOAP服务路由

时间:2013-03-22 14:57:26

标签: soap routing wso2

我有一个简单的场景,我们一直在努力实现,但我们无法弄清楚如何做到这一点。

假设我们有两个服务与dame WSDL(下面)。

我们希望在WSO2中创建一个代理,该代理公开相同的WSDL,但是根据IntValue的值将调用路由到两个后端服务之一。

IF IntValue = 1 THEN it calls
    http://localhost/WcfServiceDual_1/Service1.svc

ELSE IF IntValue = 2 THEN it calls
    http://localhost/WcfServiceDual_2/Service1.svc

之后,代理会返回来自相应(被叫)服务的响应。


<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="Service1" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost/WcfServiceDual_2/Service1.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://localhost/WcfServiceDual_2/Service1.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://localhost/WcfServiceDual_2/Service1.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/WcfServiceDual_2"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="IService1_GetData_InputMessage">
<wsdl:part name="parameters" element="tns:GetData"/>
</wsdl:message>
<wsdl:message name="IService1_GetData_OutputMessage">
<wsdl:part name="parameters" element="tns:GetDataResponse"/>
</wsdl:message>
<wsdl:message name="IService1_GetDataUsingDataContract_InputMessage">
<wsdl:part name="parameters" element="tns:GetDataUsingDataContract"/>
</wsdl:message>
<wsdl:message name="IService1_GetDataUsingDataContract_OutputMessage">
<wsdl:part name="parameters" element="tns:GetDataUsingDataContractResponse"/>
</wsdl:message>
<wsdl:portType name="IService1">
<wsdl:operation name="GetData">
<wsdl:input wsaw:Action="http://tempuri.org/IService1/GetData" message="tns:IService1_GetData_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IService1/GetDataResponse" message="tns:IService1_GetData_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="GetDataUsingDataContract">
<wsdl:input wsaw:Action="http://tempuri.org/IService1/GetDataUsingDataContract" message="tns:IService1_GetDataUsingDataContract_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IService1/GetDataUsingDataContractResponse" message="tns:IService1_GetDataUsingDataContract_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IService1" type="tns:IService1">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetData">
<soap:operation soapAction="http://tempuri.org/IService1/GetData" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetDataUsingDataContract">
<soap:operation soapAction="http://tempuri.org/IService1/GetDataUsingDataContract" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service1">
<wsdl:port name="BasicHttpBinding_IService1" binding="tns:BasicHttpBinding_IService1">
<soap:address location="http://localhost/WcfServiceDual_2/Service1.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

2 个答案:

答案 0 :(得分:0)

为什么要托管同一服务的两个实例?

无论如何,您计划在代理中使用的逻辑非常简单。从传入的请求中,只需要对要评估的参数进行扩展,并根据该路由将请求发送到不同的端点。您可以使用filter mediator进行此操作。

答案 1 :(得分:0)

我找到了解决方案:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="DualTest" transports="http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="custom" separator=",">
            <property name="MessageFlow" value="______"/>
         </log>
         <property xmlns:xs="http://schemas.datacontract.org/2004/07/WcfServiceDual_1" xmlns:p="http://tempuri.org/" name="intValue" expression="//p:GetDataUsingDataContract/p:composite/xs:IntValue/text()" scope="default" type="STRING"/>
         <property xmlns:xs="http://schemas.datacontract.org/2004/07/WcfServiceDual_1" xmlns:p="http://tempuri.org/" name="stringValue" expression="//p:GetDataUsingDataContract/p:composite/xs:StringValue/text()" scope="default" type="STRING"/>
         <log level="custom">
            <property name="intValue" expression="$ctx:intValue"/>
            <property name="stringValue" expression="$ctx:stringValue"/>
         </log>
         <log level="custom" separator=",">
            <property name="MessageFlow" value="______"/>
            <property name="MessageFlow" value="\n======================= Sending Request To : Backend ======================="/>
         </log>
         <log level="full" separator=","/>
         <filter source="get-property('intValue')" regex="2">
            <then>
               <log level="custom" separator=",">
                  <property name="IF" value="*****    2"/>
               </log>
               <send>
                  <endpoint>
                     <address uri="http://Win8/WcfServiceDual_2/Service1.svc"/>
                  </endpoint>
               </send>
            </then>
            <else>
               <log level="custom" separator=",">
                  <property name="ELSE" value="*****    1"/>
               </log>
               <send>
                  <endpoint>
                     <address uri="http://Win8/WcfServiceDual_1/Service1.svc"/>
                  </endpoint>
               </send>
            </else>
         </filter>
         <log level="custom" separator=",">
            <property name="MessageFlow" value="______"/>
         </log>
      </inSequence>
   </target>
   <publishWSDL uri="http://localhost/WcfServiceDual_1/Service1.svc?wsdl"/>
   <description></description>
</proxy>