SOAP Web Service consumer – webMethods

Overview :


In this article, we will consume the web service created earlier in the web service provider article as part of the webMethods series. In case you have not gone through the previous article, please click here to check out. We will create a web service consumer connector that facilitates the efficient invocation of specific operations within the web service. The connector will handle responses for both success and failure scenarios.

 

Prerequisites :


  • Basic understanding of SOAP protocol.
  • Basic understanding of webMethods flow services.

Code Area :


We will utilize the package created in the previous article, which demonstrates the web service provider. If you haven’t checked it out yet, click the link above to download and install the package on your server for further processing.

Folder creation :


    • Please create a folder inside the ‘soap’ directory. Refer to the package structure below, and make sure to create the folder that is marked in bold.
        • HG_WebService_Demo
          • v1
            • protocol
              • soap
                • provider
                • consumer
            • services

Create web service consumer connector :


Before creating the connector, let’s understand why it is necessary to create the web service descriptor in webMethods.

Why do we need a web service connector? :


Interface Definition :
  • A web service connector serves as a bridge between webMethods and external web services, providing a defined interface for communication.
Data Mapping and Transformation :
  • The connector facilitates the mapping and transformation of data between webMethods and the web service, ensuring compatibility and meaningful data exchange.
Reusability and Scalability :
  • Connectors can be reused across various integration scenarios as an independent service, promoting scalability and efficiency in handling multiple web service interactions.
Error Handling :
  • The connector enables effective error handling by providing mechanisms to deal with exceptions or issues that may arise during the web service interaction and return the fault document with the error details.

Create connector:


  • Before creating the consumer connector, you should have the WSDL URL or the WSDL file, as it will be required to create the connector.
  • Collect the WSDL URL by opening the provider web service descriptor and copying the WSDL URL from the properties panel.
    WSDL URL
  • Right-click on the ‘Consumer’ folder -> New -> Web service Descriptor.
  • Give the name to the descriptor as ‘consumeAdditionWS‘ and click next.
  • In the ‘Select Resource Type‘ panel, choose the descriptor type as ‘Consumer(Outbound Request)‘. You will observe that the web service source is automatically switched to ‘WSDL‘, click next.
  • Select ‘File/URL‘ option and provide the WSDL URL that you have copied in the second step and click Next->Next.
  • Note: In the above steps, you can also create it using the CentraSite URL. Ensure that the WSDL is uploaded to CentraSite, and in the designer, provide the hosted URL.
  • Select Namespace URI and click finish.
  • After completing the above step, you will notice that you have created a connector, generated the necessary service, and produced its corresponding documents.
  • In our web service, we had one operation so it created one connector, if the WSDL contains multiple operations then it will create its respective connectors in a single go.

Consume web service using connector :


Now we will create a flow service and their we will invoke our connector to consume the web service.

  • Create a flow service named ‘consumeWebService‘ inside the ‘services‘ folder.
  • Create two String variables in the input named ‘num1‘ and ‘num2‘, and create one String variable named ‘result‘ in the output.
  • Invoke ‘HG_WebService_Demo.v1.protocol.soap.Consumer.consumeAdditionWS_.connectors:additionOfTwoNum_PortType_additionOfTwoNum‘ connector inside the service and follow the below mapping.
    • tns:additionOfTwoNum/num1 -> num1.
    • tns:additionOfTwoNum/num2 ->num2.
    • auth/transport/user -> User id (which we created in the previous article, if you have not created please give your integration server username).
    • auth/transport/pass -> password (which we created in the previous article, if you have not created please give your integration server password).
    • _url -> URL of the web service.
    • tns:additionOfTwoNumResponse/sum -> result.
      Mappping
  • We have completed the development. Now, run the service with two numbers, and you will observe that it presents the sum of the two numbers in the ‘result’ variable. If you run the service with empty values, you will see that the fault document is populated with the error.

Please click on the download link below to access the source code.
Download resource

Leave a Comment