Publishing a Custom WSDL¶
When you create a proxy service, a default WSDL is automatically generated. You can access this WSDL by suffixing the service URL with ?wsdl. See the example given below, where the proxy service name is 'sample_service' and IP is localhost:
http://localhost:8290/services/sample_service?wsdl
However, this default WSDL only shows the mediate
operation. This can be a limitation because your proxy service may be
exposing a back-end service that expects additional information such as
the message format. Therefore, the proxy service should be able to
publish a custom WSDL based on the back-end service's WSDL or a modified
version of that WSDL. For example, if the back-end service expects a
message that includes the name, department, and permission level, and
you want the proxy service to inject the permission level as it
processes the message, you could publish a WSDL that includes just the
name and department without the permission level parameter.
Synapse configuration¶
Following is a sample proxy service configuration that we can used to implement this scenario. See the instructions on how to build and run this example.
<proxy name="StockQuoteProxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
<outSequence>
<send/>
</outSequence>
</target>
<publishWSDL uri="file:/path/to/sample_proxy_1.wsdl"/>
</proxy>
Build and run¶
Create the artifacts:
- Set up WSO2 Integration Studio.
- Create an Integration project.
-
Create the proxy service with the configurations given above.
Tip
Download the sample_proxy_1.wsdl file. The wsdl uri in your proxy service configuration needs to be updated with the path to this
sample_proxy_1.wsdl
file. -
Deploy the artifacts in your Micro Integrator.
Set up the back-end service:
- Download the stockquote_service.jar.
-
Open a terminal, navigate to the location of the downloaded service, and run it using the following command:
java -jar stockquote_service.jar
Set up the SoapUI client:
- Download and Install SoapUI to run this SOAP service.
- Create a new SOAP project in SoapUI using the following wsdl file:
http://localhost:8290/services/StockQuoteProxy?wsdl
Send the following payload to receive a response containing the last sales price for the stock. You can
use the getQuote
operation.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<soapenv:Header/>
<soapenv:Body>
<ser:getQuote xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<!--Optional:-->
<ser:request>
<!--Optional:-->
<xsd:symbol>IBM</xsd:symbol>
</ser:request>
</ser:getQuote>
</soapenv:Body>
</soapenv:Envelope>
You will receive the following response:
HTTP/1.1 200 OK
server: ballerina
content-encoding: gzip
content-type: application/xml
Transfer-Encoding: chunked
Connection: Keep-Alive
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://services.samples" xmlns:ax21="http://services.samples/xsd">
<soapenv:Body>
<ns:getQuoteResponse>
<ax21:change>-2.86843917118114</ax21:change>
<ax21:earnings>-8.540305401672558</ax21:earnings>
<ax21:high>-176.67958828498735</ax21:high>
<ax21:last>177.66987465262923</ax21:last>
<ax21:low>-176.30898912339075</ax21:low>
<ax21:marketCap>5.649557998178506E7</ax21:marketCap>
<ax21:name>IBM Company</ax21:name>
<ax21:open>185.62740369461244</ax21:open>
<ax21:peRatio>24.341353665128693</ax21:peRatio>
<ax21:percentageChange>-1.4930577008849097</ax21:percentageChange>
<ax21:prevClose>192.11844053187397</ax21:prevClose>
<ax21:symbol>IBM</ax21:symbol>
<ax21:volume>7791</ax21:volume>
</ns:getQuoteResponse>
</soapenv:Body>
</soapenv:Envelope>
Top