【问题标题】:how to consume wcf in node.js?如何在 node.js 中使用 wcf?
【发布时间】:2015-05-09 12:25:27
【问题描述】:

我想在 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

但它没有工作!我该如何解决我的问题?

【问题讨论】:

标签: node.js web-services wcf soap wsdl


【解决方案1】:

我遇到了这个问题,就我而言,这是因为响应被压缩了。 npm 包soap 确实指定了'Accept-Encoding': 'none',但是SOAP 服务器(由我的公司开发)表现不佳,并返回了一个gzip 压缩的正文。肥皂包不处理这个。

我正在研究的另一种方法是在createClientoptions 参数中传递我自己的httpclient 并解压缩。在 GitHub 上的 node-soap 代码测试中有一个使用自定义 httpclient 的示例:https://github.com/vpulim/node-soap/blob/master/test/client-customHttp-test.js

我还没有弄清楚如何解压缩响应,但一旦解决,我会更新这个答案。

更新

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

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 });

我通过深入研究节点肥皂代码发现了这一点。文档没有明确提及这些事情。

【讨论】:

    猜你喜欢
    • 2013-03-14
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多