2015-05-09 82 views
3

我想在node.js中使用wcf。我试了一下:如何在node.js中使用wcf?

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

但createClient(误差块)发生了错误。它说:WSDL或包含的意外根元素。 然后我试图通过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; 
    }); 

但我的程序没有调用发送功能。 最后我试图配置WCF到WSDL发布是这样的:WCF cannot configure WSDL publishing

但它没有奏效!我如何解决我的问题?

回答

1

我遇到了这个,在我的情况下,这是因为响应是gzipped。 npm包肥皂确实指定了'Accept-Encoding': 'none',但是SOAP服务器(由我公司开发)表现不佳,并发送了一个压缩的主体。肥皂包不处理这个。

我正在看的另一种方法是通过我自己的httpclient,options参数createClient并将其解压缩。有一个在GitHub节点肥皂代码测试中使用自定义httpclient的示例:https://github.com/vpulim/node-soap/blob/master/test/client-customHttp-test.js

我还没有计算出如何解压缩响应,但是一旦我解决了问题,我会更新这个答案。

更新

对于gzip压缩的反应,它更简单。您可以将所需的任何选项传递给createClientoptions对象的wsdl_options属性中的节点request调用。这包括gzip: true,这将使request为您处理gzip请求。例如

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

然后,在进行SOAP方法调用时,在回调之后将gzip参数添加到options参数中,例如,

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

我想通过挖掘节点soap代码来解决这个问题。文档没有明确提及这些事情。