简体   繁体   中英

SOAP API request works with Boomerang, but not with node-soap

I am trying to access the SOAP API which I am able to do using Boomerang easily. Here is the format of the request:

<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v="http://ws.aramex.net/ShippingAPI/v1/" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <x:Header/>
    <x:Body>
        <v:ShipmentTrackingRequest>
            <v:ClientInfo>
                <v:UserName>myUsernameHere</v:UserName>
                <v:Password>myPasswordHere</v:Password>
                <v:Version>v1.0</v:Version>
                <v:AccountNumber>MyAccNumberHere</v:AccountNumber>
                <v:AccountPin>MyPinHere</v:AccountPin>
                <v:AccountEntity>XYZ</v:AccountEntity>
                <v:AccountCountryCode>XYZ</v:AccountCountryCode>
            </v:ClientInfo>
            <v:Transaction>
                <v:Reference1>001</v:Reference1>
                <v:Reference2>?</v:Reference2>
                <v:Reference3>?</v:Reference3>
                <v:Reference4>?</v:Reference4>
                <v:Reference5>?</v:Reference5>
            </v:Transaction>
            <v:Shipments>
                <arr:string>41496248135</arr:string>
            </v:Shipments>
            <v:GetLastTrackingUpdateOnly>true</v:GetLastTrackingUpdateOnly>
        </v:ShipmentTrackingRequest>
    </x:Body>
</x:Envelope>

The request gets me all the required information. But I want to make the same request using node-soap . Here is my code:

var soap = require('soap');
var express = require('express');
var app = express();

var url = 'aramex/aramex.wsdl';
var args =  [{
    ClientInfo: 
    {
        UserName: 'myUsernameHere',
        Password: 'myPasswordHere',
        Version: 'v1.0',
        AccountNumber: 'MyAccNumberHere',
        AccountPin: 'MyPinHere',
        AccountEntity: 'XYZ',
        AccountCountryCode: 'XYZ'        
    },
    Transaction: 
      { Reference1: '001' },

    Shipments: ['41496248135']
}];

app.get('/', function(req, res){

soap.createClient(url, function(err, client) {
        client.TrackShipments(args, function(err, result, body) {
          res.send(result);
        });  
    });
})

app.listen(process.env.PORT, process.env.IP, function(){
    console.log("Server Up");
})

All I get is a huge error in the result . The body of the result object is as follows:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode><faultstring xml:lang="en-US">Error in deserializing body of request message for operation 'TrackShipments'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'ShipmentTrackingRequest' and namespace 'http://ws.aramex.net/ShippingAPI/v1/'. Found node type 'Element' with name 'ShipmentTrackingRequest' and namespace ''</faultstring><detail><ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HelpLink i:nil="true"/><InnerException><HelpLink i:nil="true"/><InnerException i:nil="true"/><Message>OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'ShipmentTrackingRequest' and namespace 'http://ws.aramex.net/ShippingAPI/v1/'. Found node type 'Element' with name 'ShipmentTrackingRequest' and namespace ''</Message><StackTrace> at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)&#xD; at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)&#xD; at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)</StackTrace><Type>System.Runtime.Serialization.SerializationException</Type></InnerException><Message>Error in deserializing body of request message for operation 'TrackShipments'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'ShipmentTrackingRequest' and namespace 'http://ws.aramex.net/ShippingAPI/v1/'. Found node type 'Element' with name 'ShipmentTrackingRequest' and namespace ''</Message><StackTrace> at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)&#xD; at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp; rpc)&#xD; at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)&#xD; at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)&#xD; at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)&#xD; at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace><Type>System.ServiceModel.CommunicationException</Type></ExceptionDetail></detail></s:Fault></s:Body></s:Envelope>

How can I fix this problem?

If it is still relevant, I encountered the same. Grab the latest WDSL file from Aramex's website.

Request args should be as follows:

let args =  [{
    ClientInfo: {
        UserName: 'myUsernameHere',
        Password: 'myPasswordHere',
        Version: 'v1.0',
        AccountNumber: 'MyAccNumberHere',
        AccountPin: 'MyPinHere',
        AccountEntity: 'XYZ',
        AccountCountryCode: 'XYZ'        
    },
    "Transaction": {
        "Reference1": "001",
        "Reference2": "002",
        "Reference3": "003",
        "Reference4": "004",
        "Reference5": "005"
    },
    "Shipments": {
            "string": awb
    },
    "GetLastTrackingUpdateOnly": false]
}];

The error you're getting is mainly because the wsdl parser is unable to match our args list with what is defined inside the WSDL file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM