Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to consume WCF soap web service in node.js

Tags:

soap

node.js

wcf

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.

like image 793
user87267867 Avatar asked Mar 25 '13 10:03

user87267867


2 Answers

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.....*/
});
like image 73
ajaysinghdav10d Avatar answered Nov 01 '22 09:11

ajaysinghdav10d


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);
    });
  });
});
like image 1
arpit desai Avatar answered Nov 01 '22 10:11

arpit desai