This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Invoke an API using the API Console as a SOAP Client

In the previous tutorial, you invoked an API using the SOAP UI. If you open the SOAP UI and click the Raw tab of the request that you sent earlier, you will note that there are two headers sent to the backend from the SOAP client as SOAPAction and Content-Type. 

An admin must add these two headers (Content-Type and SOAPAction, in this case) under the <Access-Control-Allow-Headers> element in the cross-origin resource sharing (CORS) configuration of the <APIM_HOME>/repository/conf/api-manager.xml file. Also make sure that CORS is enabled. It ensures that the API Console can make JavaScript calls to the Gateway.

<CORSConfiguration>
   <Enabled>true</Enabled>
   <Access-Control-Allow-Origin>*</Access-Control-Allow-Origin>
   <Access-Control-Allow-Methods>GET,PUT,POST,DELETE,OPTIONS</Access-Control-Allow-Methods>
   <Access-Control-Allow-Headers>tenant, enterprise, authorization, Access-Control-Allow-Origin, Content-Type, SOAPAction</Access-Control-Allow-Headers>
</CORSConfiguration>

The Swagger API Console is a JavaScript client that runs in the API Store and makes JavaScript calls from the Store to the API Gateway. Since the API Store and Gateway run on two different ports, we have enabled  (CORS) between the two. You must specify any additional headers that you want to add to the API Console under the CORS configuration.

Let's see how you can add these two headers as parameters to the API Console of the API Store, and then invoke the SOAP service via the API Console. 

  1. Log in to the API Publisher and click the API that you want to invoke (e.g., PhoneVerification).
  2. Click the Edit link next to the API's name, navigate down to the Resources section and click on the POST method to expand it.

  3. Create the following parameters that you saw earlier in the SOAP UI under the POST method using the Add Parameter button.

    Parameter nameValues
    SOAPActionDescription: Set to http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber
    Parameter Type: Header
    Data Type: String
    Required: False
    Content-TypeDescription:
    Set to text/xml
    Parameter Type: Header
    Data Type: String
    Required: False

  4. Once you are done, click Save.
  5. Log in to the API Store and click the API to open it (e.g., PhoneVerification).
  6. The API's Overview page opens. You already subscribed to the API in the previous tutorial. If in case your access token has expired now, go to the My Subscriptions page and regenerate it.
     
  7. Click on the API again to open it and then click its API Console tab. Note that the access token is already populated on the console.
  8. Expand the POST method, fill the parameter values and invoke the API. For example,

    ParameterValue
    Body

    This is the example SOAP request that we copied from the SOAP UI of the previous tutorial:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://ws.cdyne.com/PhoneVerify/query">
       <soapenv:Header/>
       <soapenv:Body>
          <quer:CheckPhoneNumber>
             <!--Optional:-->
             <quer:PhoneNumber>123456</quer:PhoneNumber>
             <!--Optional:-->
             <quer:LicenseKey>0</quer:LicenseKey>
          </quer:CheckPhoneNumber>
       </soapenv:Body>
    </soapenv:Envelope>
    SOAPActionhttp://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber
    Content-Typetext/xml

  9. Note the result that appears on the console. As you gave an invalid phone number here, the result is invalid.

You have added SOAP parameters to the API Console and invoked a SOAP service using the API Console.