Making a SOAP call with Node

I know what you’re thinking. “Are you serious? Why? Node and SOAP are completely different things. Are you high?” But in working with large companies that use older web technologies, I could not avoid having to interact with SOAP*. (Don’t even get me started on why I dislike languages like Java, C++, or .NET)

No I am not high and yes I know that Node and SOAP work in very different ways. Node is async and SOAP is synchronous. Node is lightweight, and SOAP is as heavy as Ser Gregor Clegane.

Pretty much captures their differences

I had the (unfortunate or fortune, depending what kind of dev you ask) of having to architect a way for Node to make a SOAP call. Using node-soap and Jowanza Joseph’s blog post, I was able to initiate a response.

Node-Soap Breakdown

I assume if you’re reading this, you’re familiar with require statements in node, but if not, make sure to require(‘node-soap’) in your files.

The wsdl

Working in lightweight tech has shown me how web services were done before my time. Enter the wsdl. It’s heavy. It’s cumbersome. It’s verbose. But its an important piece to the SOAP puzzle. If you open the wsdl, you’ll notice its an XML-defined schema.

For the purposes of this blog post, I’ll use an open wsdl available on the interwebz, the  Global Weather WSDL.


Node-soap requires that a soap client be created that will allow our request to be exposed to the methods defined in the wsdl. soapCreateClient takes 3 arguments.

Screen Shot 2016-05-18 at 9.33.25 PM

My example looks like this:

Screen Shot 2016-05-18 at 9.35.58 PM

Calling the SOAP methods

The next step is to have our client call the methods defined in the wsdl. It should follow this protocol:

Screen Shot 2016-05-18 at 9.40.21 PM

method is the name of the method you are trying to call that is found in the wsdl. For my example, I want to get city weather by ZIP code. My example looks like this:

Screen Shot 2016-05-18 at 9.45.40 PM

And like a good Node developer, I add error handling.

To wrap up, I leave some truth from Jowanza Joseph:

“I won’t pretend like it’s _easy _to deal with XML/ SOAP based APIs in Node.js, I wrote this post to illustrate that it’s doable. There are other folks dealing with the same issues and its not likely to go away anytime soon. The more examples we post online the more we can help each other and make the web a better place.”

Stay strong my JS heads!




*CS college grads will swear by this. And if they talk some ish about JavaScript being a scripting language, show them this


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s