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
Step 2: Added node-soap as a dependency in package.json created in earlier step
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
- require soap module
- 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
which can be access as client.ModelADService.ModelADServiceHttpPort.createData - 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 - pass these parameters to the createData function as shown below
- run the program issuing the command node main.js
This throws assertionError
Investigation Result on AssertionError while consuming SOAP services
- 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.
- 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
- lib/client.js : invoke function is modified to consider constructing the xml document for the soap request which has xsd:element in the request
- lib/wsdl.js : objectToRpcXML function is modified to construct the proper xml document which has element
- 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
123456{ignoredNamespaces: {namespaces: ['adin'],override: true}}
Follow the steps 1-3 as described above now our node program can consume the ADempiere soap services. And the output was
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 !.
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.