Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Formatted

...

  1. Log in to the API Publisher and click click ADD NEW API
  2. Select Select I Have a SOAP Endpoint. You see the following two options to create APIs for SOAP backend.
    • Pass Through  – Create a pass through proxy for SOAP requests coming to the API Gateway.
    • Generate REST APIs  – This option is used to generate REST API definitions from the given WSDL URLWSDL URL.
  3. Select Generate REST APIs. Provide the WSDL URL given below for the SOAP backend and click click Start Creating

    Code Block
    titleSample WSDL URL
    http://ws.cdyne.com/phoneverify/phoneverify.asmx?wsdl

    Image Added
    The default option is is Pass Through. Image Removed

  4. Select the Generate REST APIs option and go to the Design tab. Click on Edit Source to edit the Swagger specification of the API.
    Image Removed
  5. Click Apply Changes to

    Optionally, update the Swagger definition of your API and click Apply Changes to save your API.

    Image Removed
  6. The generated API definitions are added to the API as shown below.
    Image Removed

    Note

    The definition properties are mapped with a Swagger vendor-specific field x-xpath, which is used to map the SOAP binding operation parameters with the REST parameters. If a parameter does not have this field it is not mapped with a backend operation. To ensure the mapping functions smoothly, do not make any changes to the properties.

  7. Go to the Implement tab and view the SOAP Mapping section. Click on a resource to view the In and Out sequences of the API.
    Image Removed
  8. The following sample shows the generated API In-sequence for a GET method with query parameters.

    Code Block
    GET https://<host_name>:8243/weather/1.0.0/weather?CityName=xxxxx&CountryName=xxxxx
    Code Block<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>

    Let's update the API by replacing the existing Swagger definition with the following Swagger definition.

    Expand
    titleExpand to see the edited Swagger definition...
    Code Block
    swagger: "2.0"
    paths:
      /checkPhoneNumber:
        get:
          operationId: CheckPhoneNumber
          parameters:
            - in: query
              name: PhoneNumber
              required: true
              type: string
            - in: query
             
    <header name="SOAPAction"
     name: LicenceKey
              required: true
              type: string
          responses:
            default:
              description: ""
              schema:
                $ref: 
    scope="transport
    "#/definitions/checkPhoneNumberOutput"
          x-wso2-soap:
            
    value=
    soap-action: "http://
    www
    ws.
    webserviceX.NET/GetWeather"
    cdyne.com/PhoneVerify/query/CheckPhoneNumber"
            soap-operation: CheckPhoneNumber
            namespace: "http://ws.cdyne.com/PhoneVerify/query"
            
    description="SOAPAction"/>
    x-soap-version: "1.2"
      /checkPhoneNumbers:
        post:
          operationId: CheckPhoneNumbers
          parameters:
            - in: body
             
    <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
     name: Payload
              required: true
              schema:
                $ref: "#/definitions/checkPhoneNumbersInput"
          responses:
            default:
              description: ""
              schema:
                $ref: "#/definitions/checkPhoneNumbersOutput"
          x-wso2-soap:
            
    <property name="req.var.CityName" expression="$url:CityName"/>
    soap-action: "http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumbers"
            soap-operation: CheckPhoneNumbers
            
    <property
    namespace: 
    name="req.var.CountryName" expression="$url:CountryName"/>
    "http://ws.cdyne.com/PhoneVerify/query"
            x-soap-version: "1.2"
    info:
      title: PhoneVerificationAPI
      version: 1.0.0
    definitions:
      checkPhoneNumberInput:
        type: object
        properties:
          CheckPhoneNumber:
            $ref: "#/definitions/CheckPhoneNumber"
      checkPhoneNumberOutput:
        type: object
        properties:
          CheckPhoneNumberResponse:
            
    <payloadFactory media-type="xml" description="transform">
    $ref: "#/definitions/CheckPhoneNumberResponse"
      checkPhoneNumbersInput:
        type: object
        properties:
          CheckPhoneNumbers:
            $ref: "#/definitions/CheckPhoneNumbers"
      checkPhoneNumbersOutput:
        type: object
        properties:
          CheckPhoneNumbersResponse:
            $ref: "#/definitions/CheckPhoneNumbersResponse"
      StringArray:
        type: string
        properties:
          String:
            type: array
            items:
    
    <format>
              type: string
        
    <soapenv:Envelope xmlns:soapenv=
    xml:
          namespace: "http://
    schemas
    www.
    xmlsoap
    w3.org/
    soap
    2001/
    envelope/
    XMLSchema"
          prefix: s
      CheckPhoneNumber:
        type: object
        properties:
          PhoneNumber:
            type: string
          LicenseKey:
            type: string
        xml:
          
    xmlns
    namespace:
    web=
     "http://www.
    webserviceX.NET">
    w3.org/2001/XMLSchema"
          prefix: s
      CheckPhoneNumbersResponse:
        type: object
        properties:
          
    <soapenv:Header/>
    CheckPhoneNumbersResult:
            $ref: "#/definitions/ArrayOfPhoneReturn"
        xml:
          
    <soapenv
    namespace:
    Body>
     "http://www.w3.org/2001/XMLSchema"
          prefix: s
      ArrayOfString:
        type: object
        
    <web
    properties:
    GetWeather>
    
          string:
            type: array
            
    <web
    items:
    CityName>$1</web:CityName>
    
              type: string
        xml:
          namespace: 
    <web:CountryName>$2</web:CountryName>
    "http://www.w3.org/2001/XMLSchema"
          prefix: s
      ArrayOfPhoneReturn:
        type: object
        xml:
          
    </web:GetWeather>
    namespace: "http://www.w3.org/2001/XMLSchema"
          prefix: s
      CheckPhoneNumbers:
        type: object
        properties:
          
    </soapenv
    PhoneNumbers:
    Body>
    
            $ref: "#/definitions/ArrayOfString"
          
    </soapenv:Envelope>
    LicenseKey:
            type: string
        
    </format>
    xml:
          namespace: "http://www.w3.org/2001/XMLSchema"
        
    <args>
      prefix: s
      PhoneReturn:
        type: object
       
    <arg
     
    evaluator="xml" expression="get-property('req.var.CityName')"/>
    xml:
          namespace: "http://www.w3.org/2001/XMLSchema"
          prefix: s
      CheckPhoneNumberResponse:
        type: object
        properties:
          CheckPhoneNumberResult:
            
    <arg evaluator="xml" expression="get-property('req.var.CountryName')"/>
    $ref: "#/definitions/PhoneReturn"
        xml:
          namespace: "http://www.w3.org/2001/XMLSchema"
          prefix: s

    Image Added

  9. The generated API definitions are added to the API as shown below.
    Image Added

    Note

    A REST API method is mapped with the corresponding SOAP operation through a Swagger, vendor-specific field - x-wso2-soap. Note that this should not be edited . A parameter without this field cannot be mapped with a SOAP backend operation.

    See the sample REST operation given below.

    Code Block
      /checkPhoneNumber:
        post:
          operationId: CheckPhoneNumber
          parameters:
    
    </args>
        ...
         
    </payloadFactory>
     x-wso2-soap:
            
    <property name="messageType
    soap-action: "http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber"
            soap-operation: CheckPhoneNumber
            namespace: 
    value="application/soap+xml"
    "http://ws.cdyne.com/PhoneVerify/query"
            x-soap-version: "1.2"

    The operationId parameter is used to map the REST resource with the corresponding SOAP operation.

  10. Edit the details of the API as shown below.

    FieldSample value
    NamePhoneVerification
    Context

    /phoneverify

    Version1.0.0
    Access ControlAll
    Visibility on StorePublic
    Tags

    phone

    For more information on the meanings of the latter mentioned fields, see Create and Publish an API.

    Image Added

  11. Go to the Implement tab. Click on Managed API. 
  12. Select the Endpoint Type as the HTTP/SOAP Endpoint. Enter the SOAP endpoint URL given below.

    Code Block
    titleSOAP Endpoint URL
    http://ws.cdyne.com/phoneverify/phoneverify.asmx

    Image Added

  13. Navigate to the SOAP to REST Mapping section. Click on a resource to view the In and Out sequences of the API.
    Image Added
    The following is a sample Synapse based XML configuration which reads some parameters from the request path and constructs the SOAP payload required for the backend (target) services.

    Code Block
    <header description="SOAPAction" name="SOAPAction" scope="transport" value="http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber"/>
    <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
    <property expression="$url:PhoneNumber" name="req.var.PhoneNumber"/>
    <property  scope="axis2"expression="$url:LicenceKey" name="req.var.LicenceKey"/>
    
    
    <payloadFactory description="transform" media-type="xml">
      <format>
      <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://ws.cdyne.com/PhoneVerify/query">
      <soapenv:Header/>
      <soapenv:Body>
       type="STRING"
      	<web:CheckPhoneNumber xmlns:web="http://ws.cdyne.com/PhoneVerify/query">
       <web:PhoneNumber>$1</web:PhoneNumber>
       <web:LicenceKey>$2</web:LicenceKey>
    </web:CheckPhoneNumber>
    
      </soapenv:Body>
      </soapenv:Envelope>
      </format>
      <args>
     	<arg evaluator="xml" expression="get-property('req.var.PhoneNumber')"/>
    <arg evaluator="xml" expression="get-property('req.var.LicenceKey')"/>
    
      </args>
    </payloadFactory>
    <property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>

    The incoming JSON message parameters are stored using the property tagsproperties. The SOAP payload needed for the backend is generated using a payload factory mediator.

    Enter the SOAP endpoint URL. The endpoint type should be the HTTP/SOAP Endpoint as shown below

    .


    Image Removed

  14. Go to the the Manage tab  tab and the relevant configuration. Click Publish to select the throttling tiers for the API. Click Publish to publish the API to the API Store.
    For instructions, see Create and Publish an API.
  15. Navigate to the API Store and subscribe to an API.
    After generating the production and sandbox keys you receive a valid access token to access the API.

    https://localhost:9443/store

  16. Run the following HTTP request to invoke

    the API. 

    the API.
    You receive the actual backend response.

    Localtabgroup
    Localtab
    activetrue
    idcurl
    titlecURL command
    Code Block
    titleHTTP Request
    curl -k -X GET "https:/localhost:8243/phoneverify/1.0.0/checkPhoneNumber?PhoneNumber=1234567&LicenceKey=0" -H "accept: application/json" -H "Authorization: Bearer <access-token>"
    Localtab
    idexample
    titleExample
    Code Block
    curl -k -X GET "https:/localhost:8243/phoneverify/1.0.0/checkPhoneNumber?PhoneNumber=1234567&LicenceKey=0" -H "accept: application/json" -H "Authorization: Bearer f952e212-5247-3ae4-a974-20105068ac87"
    Localtab
    idresponse
    titleResponse
    Code Block
    {"CheckPhoneNumberResponse":{"CheckPhoneNumberResult":{"Valid":false,"OriginalNumber":1234567,"CleanNumber":234567,"Wireless":false}}}