10

I tried lot of examples available in the net using node module wcf.js. But could not get any appropriate result. I'm using the below url

https://webservice.kareo.com/services/soap/2.1/KareoServices.svc?wsdl

Any one who can explain me with the help of code will be really helpful. I want to know how to access the wsdl in node.js

Thanks.

user87267867
  • 1,409
  • 3
  • 18
  • 25
  • possible duplicate of [Node.js: how to consume SOAP XML web service](http://stackoverflow.com/questions/8655252/node-js-how-to-consume-soap-xml-web-service) – Marc Climent Apr 27 '15 at 10:45

6 Answers6

3

Please have a look at wcf.js

In short you can follow these steps:

  1. npm install wcf.js

  2. Write your code like this:

code

var Proxy = require('wcf.js').Proxy; 
var BasicHttpBinding = require('wcf.js').BasicHttpBinding; 

var binding = new BasicHttpBinding();

//Ensure the proxy variable created below has a working wsdl link that actually loads wsdl    
var proxy = new Proxy(binding, "http://YourHost/YourService.svc?wsdl");

/*Ensure your message below looks like a valid working SOAP UI request*/
var message = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:sil='http://YourNamespace'>" +
                "<soapenv:Header/>" +
                "<soapenv:Body>" +
                "<sil:YourMethod>" +
                "<sil:YourParameter1>83015348-b9dc-41e5-afe2-85e19d3703f9</sil:YourParameter1>" +
                "<sil:YourParameter2>IMUT</sil:YourParameter2>" +
                "</sil:YourMethod>" +
                "</soapenv:Body>" +
                "</soapenv:Envelope>";
/*The message that you created above, ensure it works properly in SOAP UI rather copy a working request from SOAP UI*/

/*proxy.send's second argument is the soap action; you can find the soap action in your wsdl*/
proxy.send(message, "http://YourNamespace/IYourService/YourMethod", function (response, ctx) {
    console.log(response);
    /*Your response is in xml and which can either be used as it is of you can parse it to JSON etc.....*/
});
ajaysinghdav10d
  • 1,771
  • 3
  • 23
  • 33
1

I think that an alternative would be to:

  • use a tool such as SoapUI to record input and output xml messages
  • use node request to form input xml message to send (POST) the request to the web service (note that standard javascript templating mechanisms such as ejs or mustache could help you here) and finally
  • use an XML parser to deserialize response data to JavaScript objects

Yes, this is a rather dirty and low level approach but it should work without problems

k0pernikus
  • 60,309
  • 67
  • 216
  • 347
tmanolatos
  • 932
  • 10
  • 16
1

You don't have that many options.

You'll probably want to use one of:

  • node-soap
  • douche
  • soapjs

i tried node-soap to get INR USD rate with following code.

app.get('/getcurr', function(req, res) {
var soap = require('soap');
var args = {FromCurrency: 'USD', ToCurrency: 'INR'};
var url = "http://www.webservicex.net/CurrencyConvertor.asmx?WSDL";
soap.createClient(url, function(err, client) {
    client.ConversionRate(args, function(err, result) {
        console.log(result);
    });
  });
});
1

Code Project has got a neat sample which uses wcf.js for which api's are wcf like so no need to learn new paradigm.

Sarath
  • 2,719
  • 1
  • 31
  • 39
0

You'll probably want to use one of:

Aslo, there's an existing question.

Community
  • 1
  • 1
Mehdi Bugnard
  • 3,889
  • 4
  • 45
  • 86
  • U can have look at my code in this link http://stackoverflow.com/questions/15562943/wcf-web-service-in-node-js but it throws some error. Can u plz help me in whats wrong in code? – user87267867 Mar 25 '13 at 10:21
0

In my case, I used https://www.npmjs.com/package/soap. By default forceSoap12Headers option was set to false which prevented node-soap to generate correct soap message according to SOAP 1.2. Check for more details: I am confused about SOAP namespaces. After I set it to true, I was able to make a call to .NET WCF service. Here is a TypeScript code snipper that worked for me.

import * as soap from 'soap';
import { IOptions } from 'soap';

// ...

const url = 'https://www.your-domain.com/stock.svc?wsdl';
const opt: IOptions = {
  forceSoap12Headers: true,
};

soap.createClient(url, opt, (err, client: soap.Client) => {
  if (err) {
    throw err;
  }

  const wsSecurityOptions = {
    hasTimeStamp: false,
  };

  const wsSecurity = new soap.WSSecurity('username', 'password', wsSecurityOptions);
  client.setSecurity(wsSecurity);
  client.addSoapHeader({ Action: 'http://tempuri.org/API/GetStockDetail' }, undefined, 'wsa', 'http://www.w3.org/2005/08/addressing');
  client.addSoapHeader({ To: 'https://www.your-domain.com/stock.svc' }, undefined, 'wsa', 'http://www.w3.org/2005/08/addressing');

  const args = {
    symbol: 'GOOG',
  };

  client.GetStockDetail(
    args,
    (requestErr, result) => {
      if (requestErr) {
        throw requestErr;
      }

      console.log(result);
    },
  );
});

Here couple links to the documentation of node-soap usage:

  1. https://github.com/vpulim/node-soap/tree/master/test
  2. https://github.com/vpulim/node-soap
Aliaksei Maniuk
  • 1,534
  • 2
  • 18
  • 30