Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOAP for NodeJS without using WSDL

I'm dealing with a web service that only supports SOAP. Also, I have a NodeJS application, from where I'm supposed to use this service through soap calls.

The biggest problem is, that the Web Service doesn't have a WSDL api description anywhere. So my question is, how could I with NodeJS, use Soap without WSDL? All the libraries I have checked for NodeJS so far require that I give them the WSDL url. I found one for C# that doesn't require, here: C#-soap-without-wsdl

like image 603
Ville Miekk-oja Avatar asked Aug 16 '16 15:08

Ville Miekk-oja


People also ask

Can we use SOAP node without WSDL?

You can change the Operation mode of the SOAP nodes so that they act in gateway mode. In gateway mode, a WSDL is not required to configure the nodes since they handle generic request/response and one-way SOAP messages that are not tied to a specific WSDL.

Can we call SOAP service without WSDL?

Without the WSDL, it will be responsibility of the developer to know the definition of the SOAP Web Service to consume . SOAP envelope, SOAP Body and the complete XML request has to be built by the developer and pass it to the Http client.

Does node js support SOAP?

A SOAP client and server for node. js. This module lets you connect to web services using SOAP. It also provides a server that allows you to run your own SOAP services.


1 Answers

I have also encountered this problem in the past. It is especially difficult for developers with experience using mostly RESTful APIs to grok the fundamentals of SOAP in a reasonable amount of time, let alone be able to debug issues in it. The thing to keep in mind is that SOAP uses the exact same application layer protocol (HTTP) as the RESTful APIs you're probably used to working with. There will be headers, a uri, a method just like what you're used to, the only thing special being the way that you format these fields.

After realizing this, the solution I eventually arrived at was to generate the few SOAP requests (think it was two) I needed using a desktop SOAP tool like SoapUI and then simply send these generated requests using a non-SOAP HTTP request library for node.

Here's an example that consistently worked for me:

// SOAP
var requestBody =
  '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +
  'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><soap:Header>' +
  '<SOAPAction>addRoom' +
  '</SOAPAction></soap:Header><soap:Body><AddRoomRequest ' +
  'xmlns="http://portal.vidyo.com/admin/v1_1"><room><name>' +
  params.conferenceName + '</name><RoomType>Public</RoomType><ownerName>' +
  vidyoApiUsername  + '</ownerName>' + '<extension>' +
  params.conferenceExtension  +
  '</extension><groupName>Default</groupName><RoomMode><isLocked>' +
  'false</isLocked><hasPIN>false</hasPIN><hasModeratorPIN>false' +
  '</hasModeratorPIN></RoomMode></room></AddRoomRequest></soap:Body>' +
  '</soap:Envelope>';

var requestHeaders = {
  'cache-control': 'no-cache',
  'soapaction': 'addRoom',
  'content-type': 'text/xml;charset=UTF-8'
};

var requestOptions = {
  'method': 'POST',
  'url': vidyoApiEndpoint,
  'qs': { 'wsdl': ''},
  'headers': requestHeaders,
  'body': requestBody,
  'timeout': 5000
};

request(requestOptions, function (error, response, body) {
  if (error) {
    // handle error
  } else {
    try {
      var parsingOptions = {
        'object': true,
        'sanitize': false
      };
      var jsonResult = parser.toJson(body, parsingOptions); // from xml
      if(jsonResult['soapenv:Envelope']
        ['soapenv:Body']
        ['ns1:AddRoomResponse']
        ['ns1:OK'] === 'OK') {
          conferenceInfo(req, res, next, params);
      } else {
       // handle error
      }
    } catch (e) {
      // handle error
    }
   }
}).auth(vidyoApiUsername, vidyoApiPassword); 
// you can remove this .auth if your api has no authentication

UPDATE: The bottom line is that this is a workaround which helps explain to a beginner how SOAP works compared to other requests. This is not meant to be a recommendation as a best practice, but rather information which could help a developer understand the issue at hand.

like image 165
ztech Avatar answered Sep 20 '22 15:09

ztech