【问题标题】:WSO2 API Manager convert SOAP to RESTWSO2 API Manager 将 SOAP 转换为 REST
【发布时间】:2013-01-24 15:37:25
【问题描述】:

是否可以直接在 API 管理器中将 SOAP 服务作为 REST API 发布?是否可以在调用 SOAP 时转换调用并将 REST 公开给最终用户?

如果可能,怎么做?
谢谢。

【问题讨论】:

    标签: rest soap wso2 wso2-am


    【解决方案1】:

    这可能是您正在寻找的。这可以如下所述完成。

    如果您想以 RESTful 方式使用同一 API 公开多个操作,您可以使用以下准则修改 post 中的序列。

    1) 在 API Manager 中设计 REST API 时,创建一个请求 URI 以映射到后端 SOAP 服务中的每个操作。

    2) 使用过滤器中介器(在编程中充当条件语句),您可以从请求 URI(操作)中过滤掉并相应地构造所需的有效负载。

    将根据您映射后端 Web 服务的各种操作重复以下块。

    这里的逻辑是如果 API 的请求 URI 是 X 路由到 SOAP 服务的操作 Y。

    <!-- this filters out the operations of your API -->
    
    <property expression="json-eval($.operation)" name="operation" />
    <filter regex="menu" source="$ctx:operation">
    
       <header description="SOAPAction" name="SOAPAction" scope="transport" value="http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber"/>
    
    <!-- We are storing the input values which the end users input for these values into properties -->
    
    <property name="uri.var.phoneNumber" expression="$url:PhoneNumber"/>
    <property name="uri.var.licenseKey" expression="$url:LicenseKey"/>
    
    <!-- Since we do not want the URL pattern we mentioned to be sent to the backend we need to add the below property to remove it -->
    
    <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
    
    <!-- Now we need to create the actual payload which the backend requires. For that we use the payload factory mediator -->
    
    <payloadFactory description="transform" media-type="xml">
      <format>
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://ws.cdyne.com/PhoneVerify/query">
      <soapenv:Header/>
      <soapenv:Body>
      <quer:CheckPhoneNumber>
        <quer:PhoneNumber>$1</quer:PhoneNumber>
        <quer:LicenseKey>$2</quer:LicenseKey>
      </quer:CheckPhoneNumber></soapenv:Body>
      </soapenv:Envelope>
      </format>
      <args>
        <arg expression="get-property(‘uri.var.phoneNumber’)"/>
        <arg expression="get-property(‘uri.var.licenseKey’)"/>
      </args>
    </payloadFactory>
    

    有关上述用例的更多信息,您可以参考post 作为参考,了解如何使用这种自定义扩展序列来映射后端 SOAP Web 服务操作。有了这个,您就可以直接将其公开为 REST API

    或者您可以简单地在 WSO2 API Cloud 或 WSO2 API 管理器中创建一个基于 SOAP 的 API,然后将请求负载与 SOAP Action 标头中发送的 SOAP 操作一起传递,以便您可以调用后端 Web 的不同操作服务。您可以在下图中看到它是如何使用的。

    Managing WSDL operations using a single API

    希望这会有所帮助。

    问候。

    【讨论】:

      【解决方案2】:

      是的。您可以参考此blog post 作为参考。请注意,由于这是为 API manager Alpha 版本编写的,因此可能存在一些差异。然而,这是一个很好的切入点。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-18
        • 2013-05-19
        • 1970-01-01
        相关资源
        最近更新 更多