Fiona.W
Fiona.W

Reputation: 11

How to create wsdl soap request using nodejs soap

I used node.js soap to send a soap request, but I am keeping getting the error.

In SoapUI my xml looks like this:

<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>

Here is my code:

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

    });
});

Here is the error:

a:InternalServiceFault Bad Api Key

Please someone help me on this?

Upvotes: 1

Views: 1831

Answers (2)

Fiona.W
Fiona.W

Reputation: 11

I have made it work using strong-soap.

Here is the code:

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

(This is the return of client.describe():

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

)

Upvotes: 1

Boliang Tan
Boliang Tan

Reputation: 1

It seems you have to use a namespace for your apiKey and orderId. You need to see in your soapclient sdk how to setup namespaces

Upvotes: 0

Related Questions