SOAP for NodeJS without using WSDL

I am dealing with a web service that only supports SOAP. In addition, I have a NodeJS application, from where I have to use this service using soap calls.

The biggest problem is that the web service does not have a WSDL-api description anywhere. So my question is: how could I use Soap without WSDL with NodeJS? All the libraries I checked for NodeJS require me to give them the WSDL URL. I found one for C # that doesn’t require, here: C # -soap-without-wsdl

+4
source share
1 answer

I also encountered this problem in the past. It is especially difficult for developers with experience using mostly RESTful APIs to get the basics of SOAP in a reasonable amount of time, not to mention the possibility of debugging problems in it. Keep in mind that SOAP uses the same application level protocol (HTTP) as the RESTful API that you are probably used to working with. There will be headers, uri, method, as well as what you are used to, the only thing that is especially important in how you format these fields.

After implementing this solution, I eventually came up with a few SOAP requests (I think it was two), I needed to use a SOAP tool for my desktop PC like SoapUI , and then just send these generated requests using a non-SOAP HTTP request library for node .

, :

// 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: , , , SOAP . , , .

+8

Source: https://habr.com/ru/post/1651427/


All Articles