【问题标题】:SOAP API request works with Boomerang, but not with node-soapSOAP API 请求适用于 Boomerang,但不适用于 node-soap
【发布时间】:2016-07-21 17:47:28
【问题描述】:

我正在尝试使用 Boomerang 轻松访问 SOAP API。这是请求的格式:

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

该请求为我提供了所有必需的信息。但我想使用node-soap 发出相同的请求。这是我的代码:

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

我得到的只是result 中的一个巨大错误。 result 对象的主体如下:

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

我该如何解决这个问题?

【问题讨论】:

    标签: node.js wcf soap node-soap aramex


    【解决方案1】:

    如果它仍然相关,我遇到了同样的情况。从 Aramex 网站获取最新的 WDSL 文件。

    请求参数如下:

    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]
    }];
    

    您遇到的错误主要是因为 wsdl 解析器无法将我们的 args 列表与 WSDL 文件中定义的内容相匹配。

    【讨论】:

    • 'Shipments' 例如应该是一个字符串数组,所以这是错误的。
    猜你喜欢
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    • 2021-09-06
    • 1970-01-01
    • 2019-07-03
    • 1970-01-01
    相关资源
    最近更新 更多