2013-03-25 77 views
6

我尝试了很多使用节点模块wcf.js的网络示例。但无法得到任何适当的结果。我使用下面的链接如何在node.js中使用WCF soap web服务

https://webservice.kareo.com/services/soap/2.1/KareoServices.svc?wsdl

任何一个谁可以解释我的代码的帮助将是非常有益的。我想知道如何访问node.js中的wsdl

谢谢。

+0

的可能重复[Node.js的:如何消费SOAP XML Web服务(http://stackoverflow.com/questions/8655252/node-js-how-to-consume-soap-xml-web-service) – 2015-04-27 10:45:22

回答

0

你可能会想使用一个:

ASLO,有an existing question

+0

你可以看看我的代码在这个链接http://stackoverflow.com/questions/15562943/wcf-web- service-in-node-js,但会引发一些错误。你可以帮我解决代码中的错误吗? – user87267867 2013-03-25 10:21:39

0

我认为一个替代方案将是:

  • 使用工具如SoapUI记录输入和输出的XML消息
  • 使用node request以形成输入XML消息发送(POST)的请求,以Web服务(请注意,标准的JavaScript模板机制,如ejsmustache可以帮助你在这里),最后
  • 使用XML解析器来响应数据反序列化JavaScript对象

是的,这是一个相当脏,低水平的方法,但它应该没有问题

1

你没有那么多的选择。

你可能会想使用一个:

  • 节点皂
  • 冲洗
  • soapjs

我试图节点皂获得INR美元汇率与下面的代码。

app.get('/getcurr', function(req, res) { 
var soap = require('soap'); 
var args = {FromCurrency: 'USD', ToCurrency: 'INR'}; 
var url = "http://www.webservicex.net/CurrencyConvertor.asmx?WSDL"; 
soap.createClient(url, function(err, client) { 
    client.ConversionRate(args, function(err, result) { 
     console.log(result); 
    }); 
    }); 
}); 
1

代码项目已经得到了neat sample它使用wcf.js用于其API的是WCF像这样不需要学习新的范例。

0

请看看wcf.js

总之你可以按照下列步骤操作:

  1. NPM安装WCF。JS

  2. 撰写您这样的代码:

代码

var Proxy = require('wcf.js').Proxy; 
var BasicHttpBinding = require('wcf.js').BasicHttpBinding; 

var binding = new BasicHttpBinding(); 

//Ensure the proxy variable created below has a working wsdl link that actually loads wsdl  
var proxy = new Proxy(binding, "http://YourHost/YourService.svc?wsdl"); 

/*Ensure your message below looks like a valid working SOAP UI request*/ 
var message = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:sil='http://YourNamespace'>" + 
       "<soapenv:Header/>" + 
       "<soapenv:Body>" + 
       "<sil:YourMethod>" + 
       "<sil:YourParameter1>83015348-b9dc-41e5-afe2-85e19d3703f9</sil:YourParameter1>" + 
       "<sil:YourParameter2>IMUT</sil:YourParameter2>" + 
       "</sil:YourMethod>" + 
       "</soapenv:Body>" + 
       "</soapenv:Envelope>"; 
/*The message that you created above, ensure it works properly in SOAP UI rather copy a working request from SOAP UI*/ 

/*proxy.send's second argument is the soap action; you can find the soap action in your wsdl*/ 
proxy.send(message, "http://YourNamespace/IYourService/YourMethod", function (response, ctx) { 
    console.log(response); 
    /*Your response is in xml and which can either be used as it is of you can parse it to JSON etc.....*/ 
});