如何使用nodejs soap创建wsdl soap请求

时间:2017-06-15 15:23:21

标签: node.js xml soap wsdl

我使用node.js soap发送soap请求,但我一直在收到错误。

在SoapUI中,我的xml看起来像这样:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:acl="http://schemas.datacontract.org/2004/07/Acl.WcfService.Model">
<soapenv:Header/>
<soapenv:Body>
      <tem:GetOrder>
         <!--Optional:-->
         <tem:args>
            <!--Optional:-->
            <acl:ApiKey></acl:ApiKey>
            <!--Optional:-->
            <acl:OrderId></acl:OrderId>
         </tem:args>
      </tem:GetOrder>
   </soapenv:Body>
</soapenv:Envelope>

这是我的代码:

var args = {
    'args': {
        'ApiKey' : '***',
        'OrderId' : '***'
    }
};

soap.createClient(wsdlURL, function (err, soapClient) {

    soapClient.GetOrder(args, function (err, result) {
        //the result goes here
        if (err) {
            console.log(err);
            return;
        }

        console.log(result);

    });
});

这是错误:

一个:InternalServiceFault Bad Api Key

请有人帮帮我吗?

2 个答案:

答案 0 :(得分:1)

我使用强力肥皂使它发挥作用。

以下是代码:

"use strict";

var soap = require('strong-soap').soap;
var url = 'http://acldev.azurewebsites.net/CmsService.svc?singleWsdl';
var requestArgs = {
    args: {
        ApiKey : '***',
        OrderId : '***'
    }
};
var options = {};
soap.createClient(url, options, function(err, client) {
    var method = client['CmsService']['BasicHttpBinding_ICmsService']['GetOrder'];
    method(requestArgs, function(err, result, envelope, soapHeader) {
    //response envelope
        console.log('Response Envelope: \n' + envelope);
    //'result' is the response body
        console.log('Result: \n' + JSON.stringify(result));
    });
});

(这是client.describe()的回复:

{ CmsService:
{ BasicHttpBinding_ICmsService: 
{ GetOrders: [Object], GetOrder: [Object] },
 BasicHttpBinding_ICmsService1: { GetOrders: [Object], GetOrder: [Object] } } }

答案 1 :(得分:0)

您似乎必须为apiKey和orderId使用命名空间。您需要在soapclient sdk中查看如何设置命名空间