2015-05-09 37 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代碼來解決這個問題。文檔沒有明確提及這些事情。