Scroll Top

Consuming Soap Service in NodeJs

Sop

Problem Statement

Quite recently, I laid hands in building an application that would comprise of ExtJS and Node.js. This application needs to communicate with various third party applications through SOAP services.

One of the third party applications that I need to take into consideration is ADempiere. However, while consuming default ADempiere SOAP services I came across a few issues. In this article, we will see how to consume SOAP services from node.js application and also find out how I fixed the issues that I was facing.

Pre-Requisites

  • Node.js
  • node-soap
  • SOAP services to consume

Implementation Details

There is a package/module available in node to consume any soap services i.e node-soap.

Let us see how I  tried using the node-soap module.

Step 1:Initiated a node application using npm init. Inside a new directory I have created for this sample with the name adempiere-node

Screen Shot 2016-06-14 at 6.13.31 pm

Step 2: Added node-soap as a dependency in package.json created in earlier step

Screen Shot 2016-06-14 at 6.15.07 pm

Here node-soap module package name is “soap” and the current version is 0.15.0

Issue “npm install” command under the same directory, soap module will be installed locally.

Step 3: Write main program to consume the service createData of type createInterest

  1. require soap module
  2. soap.createClient(url,callback(err,client)) : This function will read the wsdl of the given url and reflect the services,binding port and operations under the port which you can access as functions as the child properties of the client.
    Ex: The wsdl has ModelAdService which ModelADServiceHttpPort which has createData Operation as shown
    Screen Shot 2016-06-14 at 6.31.29 pm
    which can be access as client.ModelADService.ModelADServiceHttpPort.createData
  3. identify the arguments from WSDL or client.describe().ModelAdService.ModelADServiceHTTPPort.createData in the main program.
    Identified the request xml from the WSDL file and converted it to JSON format which looks like below
    Screen Shot 2016-06-14 at 6.44.22 pm
  4.  pass these parameters to the createData function as shown below
    Screen Shot 2016-06-14 at 6.21.50 pm
  5. run the program issuing the command node main.js
    This throws assertionError
    Screen Shot 2016-06-14 at 6.49.46 pm

Investigation Result on AssertionError while consuming SOAP services

  1. ADempiere soap service has <xsd:element> in <xsd:complexType> which does not seem to be considered while preparing the request soap envelop and in constructing the parameters in the client.describe function of node-soap module.
    Screen Shot 2016-06-14 at 8.10.34 pm
  2. As <xsd:element> is not considered while constructing the xml document for the soap request throws AssertionError in client.js Client.invoke function

Fixes to the node-soap module

  1. lib/client.js  : invoke function is modified to consider constructing the xml document for the soap request which has xsd:element in the request
  2. lib/wsdl.js : objectToRpcXML function is modified to construct the proper xml document which has element
  3. After fixing this identified that namespace is missing in the xml document generated which is due to the ignoredNameSpaces has “tns” as default name space to be ignored. This should be overrided  with passing the below object as second argument to soap.client function

Follow the steps 1-3 as described above now our node program can consume the ADempiere soap services. And the output was

Screen Shot 2016-06-14 at 8.32.53 pm

These fixes are pushed to node-soap git repository and the changes were merged to the master repo. Commit for reference.

I would like to thank Joseph Spencer and Heinz Romirer for spending their valuable time in helping me to contribute my changes to node-saop repository.

You may try out the code on GitHub, and let me know how it went !

Summary

In this article, we have learned how to consume soap services in Node.js application. This sample has soap module internally with my fixes. Next release of node-soap will have these fixes.

Happy coding !.

References

Comments (2)

hi, can you help me create a SOAP web service example, backend with nodejs+express and frontend with angular .Thank you

how to consume wshttpbinding in nodejs? you have any idea.

Leave a comment

Privacy Preferences
When you visit our website, it may store information through your browser from specific services, usually in form of cookies. Here you can change your privacy preferences. Please note that blocking some types of cookies may impact your experience on our website and the services we offer.