Reputation: 31
I want to consume wcf in node.js. I tried it:
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). it says: Unexpected root element of WSDL or include . Then I tried by 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 didn't call send function. Finally I tried to configure WCF to WSDL publishing like this: WCF cannot configure WSDL publishing
But it didn't work to! How can I solve my problem?
Upvotes: 3
Views: 2502
Reputation: 1368
I ran into this and in my case it's because the response is gzipped. The npm package soap does specify 'Accept-Encoding': 'none'
but the SOAP server (developed by my company) is not well behaved and sends back a gzipped body. The soap package doesn't handle this.
One alternative I'm looking at is to pass my own httpclient
in the options
parameter of createClient
and unzip it. There is an example of using a custom httpclient in the tests for the node-soap code on GitHub: https://github.com/vpulim/node-soap/blob/master/test/client-customHttp-test.js.
I haven't worked out how to unzip the response yet, but I'll update this answer once I work it out.
Update
For gzipped responses, it's simpler. You can pass any options you want to the node request
call in the wsdl_options property of the createClient
options
object. This includes gzip: true
, which will make request
handle gzipped requests for you. e.g.
soap.createClient('http://someservice.com/?wsdl',
{ wsdl_options: { gzip: true } },
function (err, client) {});
Then when making SOAP method calls, add the gzip parameter to the options argument after your callback e.g.
client.someSoapCall({arg1:"12345"},
function (err, result) {},
{ gzip: true });
I figured this out by digging into the node soap code. The docs do not explicitly mention these things.
Upvotes: 1