8

我使用节点模块 wcf.js 尝试了很多网络中可用的示例。但无法得到任何适当的结果。我正在使用以下网址

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

任何可以在代码的帮助下向我解释的人都会非常有帮助。我想知道如何访问 node.js 中的 wsdl

谢谢。

4

6 回答 6

2

请看一下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.....*/
});
于 2017-07-20T08:55:43.163 回答
1

你没有那么多选择。

您可能想要使用以下之一:

  • 节点肥皂
  • 冲洗
  • 肥皂剧

我尝试使用 node-soap 使用以下代码获取 INR USD 汇率。

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);
    });
  });
});
于 2014-05-29T06:49:58.027 回答
1

Code Project 有一个简洁的示例,它使用wcf.js,其中 api 类似于 wcf,因此无需学习新的范例。

于 2014-06-28T17:05:57.793 回答
1

我认为另一种选择是:

  • 使用SoapUI之类的工具来记录输入输出xml消息
  • 使用节点请求形成输入 xml 消息以将请求发送 (POST) 到 Web 服务(请注意,标准的 javascript 模板机制,如ejsmustache可以在这里为您提供帮助),最后
  • 使用 XML 解析器将响应数据反序列化为 JavaScript 对象

是的,这是一种相当肮脏和低级的方法,但它应该可以毫无问题地工作

于 2014-04-06T17:29:52.290 回答
0

您可能想要使用以下之一:

另外,还有一个问题

于 2013-03-25T10:15:43.120 回答
0

就我而言,我使用了https://www.npmjs.com/package/soap。根据 SOAP 1.2,默认forceSoap12Headers选项设置为false阻止node-soap生成正确的肥皂消息。检查更多细节:我对 SOAP namespaces 感到困惑。将其设置为 后true,我能够调用 .NET WCF 服务。这是一个对我有用的 TypeScript 代码剪辑器。

import * as soap from 'soap';
import { IOptions } from 'soap';

// ...

const url = 'https://www.your-domain.com/stock.svc?wsdl';
const opt: IOptions = {
  forceSoap12Headers: true,
};

soap.createClient(url, opt, (err, client: soap.Client) => {
  if (err) {
    throw err;
  }

  const wsSecurityOptions = {
    hasTimeStamp: false,
  };

  const wsSecurity = new soap.WSSecurity('username', 'password', wsSecurityOptions);
  client.setSecurity(wsSecurity);
  client.addSoapHeader({ Action: 'http://tempuri.org/API/GetStockDetail' }, undefined, 'wsa', 'http://www.w3.org/2005/08/addressing');
  client.addSoapHeader({ To: 'https://www.your-domain.com/stock.svc' }, undefined, 'wsa', 'http://www.w3.org/2005/08/addressing');

  const args = {
    symbol: 'GOOG',
  };

  client.GetStockDetail(
    args,
    (requestErr, result) => {
      if (requestErr) {
        throw requestErr;
      }

      console.log(result);
    },
  );
});

这里有几个node-soap使用文档的链接:

  1. https://github.com/vpulim/node-soap/tree/master/test
  2. https://github.com/vpulim/node-soap
于 2020-08-11T05:04:44.980 回答