How to consume wcf in node.js?

I want to use wcf in node.js. I tried:

soap.createClient(url, function (err, client) { if (err) { console.log(err); return false; } client.myFunc(args, function(err1, result) { if(result.success) return true; }); });

But an error occurred in createClient (error block). he says: Unexpected root element of WSDL or include. Then I tried wcf.js:

 var BasicHttpBinding = require('wcf.js').BasicHttpBinding , Proxy = require('wcf.js').Proxy , binding = new BasicHttpBinding() , proxy = new Proxy(binding, " http://localhost/myService.svc"); var message = '<Envelope xmlns=' + '"http://schemas.xmlsoap.org/soap/envelope/">' + '<Header />' + '<Body>' + '<myFunc xmlns="http://localhost/myService.svc/">' + '<value>'+ args +'</value>' + '</AddNewUser>' + '</Body>' + '</Envelope>'; proxy.send(message, "http://localhost/myService.svc", function (result, ctx){ if(result.success) return true; }); 

But my program did not call the send function. Finally, I tried to configure WCF publishing to WSDL as follows: WCF cannot configure WSDL publishing

But it didn’t work! How can I solve my problem?

+3
soap wsdl web-services wcf
source share
1 answer

I came across this in my case too, because the answer was gzipped. The soap for the npm package indicates 'Accept-Encoding': 'none' , but the SOAP server (developed by my company) does not behave very well and sends the gzipped body back. Soap bag does not cope with this.

One of the alternatives I'm looking for is to pass my own httpclient into the options createClient parameter and unzip it. An example of using custom httpclient in tests for node-sap code on GitHub: https://github.com/vpulim/node-soap/blob/master/test/client-customHttp-test.js .

I have not yet decided how to unzip the answer again, but I will update this answer after developing it.

Update

For gzipped answers this is easier. You can pass any parameters that you want to call node request in the wsdl_options property of the createClient options object. This includes gzip: true , which will make request handle gzipped requests for you. eg.

 soap.createClient('http://someservice.com/?wsdl', { wsdl_options: { gzip: true } }, function (err, client) {}); 

Then, when calling the SOAP method, add the gzip parameter to the parameter argument after your callback, for example.

 client.someSoapCall({arg1:"12345"}, function (err, result) {}, { gzip: true }); 

I figured this out by digging into node soap code. The documents do not explicitly mention these things.

+1
source share

All Articles