...
- Log in to the API Publisher and click ADD NEW API
- 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 URL.
Select Generate REST APIs. Provide the WSDL URL given below for the SOAP backend and click Start Creating.
Code Block title Sample WSDL URL http://ws.cdyne.com/phoneverify/phoneverify.asmx?wsdl
The default option is Pass Through.Go to the Design tab. Click on Edit Source to edit Optionally, update the Swagger specification of the API.
Copy and paste the following codedefinition of your API and click Apply Changes to save your API.Let's update the API by replacing the existing Swagger definition with the following Swagger definition.
Click Apply Changes to save your API.Expand title Expand to see the edited Swagger definition...
get:Code Block swagger: "2.0" paths: /checkPhoneNumber: get: operationId: CheckPhoneNumber parameters:
200":- in: query name: PhoneNumber required: true type: string - in: query name: LicenceKey required: true type: string responses: default: description: "
description" schema:
produces$ref: "#/definitions/checkPhoneNumberOutput"
application/xmlx-wso2-soap: soap-
consumes:action: "http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber" soap-operation: CheckPhoneNumber namespace:
application/json"http://ws.cdyne.com/PhoneVerify/query" x-soap-
nameversion: "1.2" /checkPhoneNumbers: post: operationId: CheckPhoneNumbers parameters: -
Phone Numberin:
inbody
queryname:
type: stringPayload required: true schema:
Give the phone number to be validated$ref: "#/definitions/checkPhoneNumbersInput" responses: default: description: "
name" schema: $ref: "#/definitions/checkPhoneNumbersOutput" x-wso2-soap: soap-action: "http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumbers" soap-
LicenseKey"operation: CheckPhoneNumbers namespace: "http://ws.cdyne.com/PhoneVerify/query" x-soap-version: "
in: query1.2" info: title: PhoneVerificationAPI version: 1.0.0 definitions: checkPhoneNumberInput: type: object properties: CheckPhoneNumber: $ref: "#/definitions/CheckPhoneNumber"
requiredcheckPhoneNumberOutput: type: object properties:
trueCheckPhoneNumberResponse:
string$ref: "#/definitions/CheckPhoneNumberResponse" checkPhoneNumbersInput: type: object properties:
descriptionCheckPhoneNumbers:
Give the license key as 0 for testing purpose" post:$ref: "
parameters#/definitions/CheckPhoneNumbers" checkPhoneNumbersOutput: type: object properties: CheckPhoneNumbersResponse: $ref: "#/definitions/CheckPhoneNumbersResponse" StringArray: type: string properties: String: type: array items: type: string
-xml: namespace: "http://www.w3.org/2001/XMLSchema"
name
Payloadprefix:
descriptions CheckPhoneNumber: type: object
Requestproperties:
Body
requiredPhoneNumber:
falsetype:
instring LicenseKey:
bodytype: string
schema:xml: namespace:
payload"http://www.w3.org/2001/XMLSchema" prefix: s CheckPhoneNumbersResponse: type: object properties: CheckPhoneNumbersResult: $ref: "#/definitions/ArrayOfPhoneReturn" xml: namespace: "http://www.w3.org/2001/XMLSchema" prefix: s ArrayOfString: type: object properties: string:
responses:type: array items: type: string xml:
200":namespace: "http://www.w3.org/2001/XMLSchema" prefix: s ArrayOfPhoneReturn: type: object xml: namespace: "http://www.w3.org/2001/XMLSchema" prefix: s CheckPhoneNumbers: type: object properties: PhoneNumbers: $ref: "
description#/definitions/ArrayOfString" LicenseKey: type: string xml:
info:namespace: "http://www.w3.org/2001/XMLSchema"
titleprefix: s PhoneReturn: type: object
PhoneVerificationxml:
version
1.0.0namespace:
"http://www.w3.org/2001/XMLSchema" prefix: s CheckPhoneNumberResponse: type: object properties: CheckPhoneNumberResult: $ref: "#/definitions/PhoneReturn" xml: namespace: "http://www.w3.org/2001/XMLSchema" prefix: s
The generated API definitions are added to the API as shown below.
Go to the Implement tab and view the SOAPNote The definition properties are A REST API method is mapped with the corresponding SOAP operation through 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.-
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: ... x-wso2-soap: soap-action: "http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber" soap-operation: CheckPhoneNumber namespace: "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.Edit the details of the API as shown below.
Field Sample value Name PhoneVerification Context /phoneverify
Version 1.0.0 Access Control All Visibility on Store Public Tags phone
For more information on the meanings of the latter mentioned fields, see Create and Publish an API.
- Go to the Implement tab. Click on Managed API.
Select the Endpoint Type as the HTTP/SOAP Endpoint. Enter the SOAP endpoint URL given below.
Code Block title SOAP Endpoint URL http://ws.cdyne.com/phoneverify/phoneverify.asmx
Navigate to the SOAP to REST Mapping section. Click on a resource to view the In and Out sequences of the API.
The following sample shows the generated API In-sequence for a GET method with query parameters.
Code Block GET https://<host_name>:8243/phoneverify/1.0.0/CheckPhoneNumber?Phone%20Number=XXXXXXXX&LicenseKey=0
Code Block 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 expression="$url:LicenseKeyLicenceKey" name="req.var.LicenseKeyLicenceKey"/> <payloadFactory description="transform" media-type="xml"> <format> <soapenv:Envelope xmlns:soapenv="http://schemaswww.xmlsoapw3.org/2003/05/soap/-envelope/" xmlns:web="http://ws.cdyne.com/PhoneVerify/query"> <soapenv:Header/> <soapenv:Body> <web:CheckPhoneNumber xmlns:web="http://ws.cdyne.com/PhoneVerify/query"> <web:PhoneNumber>$1</web:PhoneNumber> <web:LicenseKey>$2<LicenceKey>$2</web:LicenseKey>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.LicenseKeyLicenceKey')"/> </args> </payloadFactory> <property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
The incoming JSON message parameters are stored using properties. 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.
Go to the Manage tab and select the relevant configurationsthe throttling tiers for the API. Click Publish to publish the API to the API Store.Code Block title SOAP Endpoint URL http://ws.cdyne.com/phoneverify/phoneverify.asmx
For instructions, see Create and Publish an API.Navigate to the API Store and
invoke the API.subscribe to an API.
After generating the production and sandbox keys you receive a valid access token to access the API.Run the following HTTP request to invoke the API.
You receive the actual backend response.Localtabgroup Localtab active true id curl title cURL command Code Block title HTTP 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 id example title Example 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 id response title Response Code Block {"CheckPhoneNumberResponse":{"CheckPhoneNumberResult":{"Valid":false,"OriginalNumber":1234567,"CleanNumber":234567,"Wireless":false}}}