soapwsdlnode-soap

When creating a SOAP client in node-soap, what is the WSDL used for?


On server side the wsdl is used to build/describe the soap api, however, when using the node-soap to make a soap client - what is the wsdl used for?

This guy seems to write every tiny bit of the XML as JSON and adding it all as arguments in the method call - Shouldn't the WSDL and node-soap package do some magic here to simplify the arguments needed for the request?


Solution

  • When you have a SOAP web service, you have to send messages using SOAP... obviously.

    That means that from whatever programming language you make a call, or from whatever programming language you build a response, you need to marshal and unmarshal objects to SOAP XML and vice-versa.

    Because SOAP is a protocol, it is strict on how those XML messages must look. And because there are strict rules, you can have tools generate those messages and handle that marshal/unmarshal for you automatically, if only you had some description of the service's API that can be used by the tools. And here is where the WSDL enters.

    The WSDL describes the contract exposed by the SOAP web service, and at the same time, the contract clients need to respect in order to make the calls. With appropriate tools, you can generate skeleton code on the server and stub code on the client from the WSDL to handle the SOAP communication for you. That can be done statically by generating code, or dynamically by reading the WSDL during execution and exposing methods that you can use to invoke the service's operations.

    So, to answer your question, node-soap on the client side creates a dynamic client by reading the WSDL and then allows you to call SOAP operations on the web service like JavaScript methods, instead of bothering to write SOAP XML by hand. You can obviously build that SOAP XML by hand if you don't have a client, but if you have a client already you should use that as it keeps things more clean.