如何格式化SOAP参数

时间:2018-08-02 09:12:34

标签: javascript reactjs soap

我在传出xml soap请求时遇到问题。 我试图将参数设置为数组中的属性。 但是如何正确格式化呢?

如果我将params设置为xml,一切都很好

 var url = this.props.serverAddress+'/ReportsListsService?wsdl';

        var args = `<GetAdditionalTrainDispatchListItems
        xmlns="http://tempuri.org/">
        <from>`+Date1+`</from>
        <to>`+enDate+`</to>
        <clientID>0</clientID>
        </GetAdditionalTrainDispatchListItems>`;


        var header = {tt4tServiceSessionID: sessionid}
            soap.createClient(url, function(err, client) {
            client.addSOAPHeader(header);
            client.GetAdditionalTrainDispatchListItems(args, function(err, result,) {
};

传出xml

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract">
<soap:Header>
<tt4tServiceSessionID>4e6de8d4-28c1-4494-a080-afca1d285819</tt4tServiceSessionID>
</soap:Header>
<soap:Body>
<GetAdditionalTrainDispatchListItems
        xmlns="http://tempuri.org/">
        <from>2018-07-29</from>
        <to>2018-08-02T10:23:59+02:00</to>
        <clientID>0</clientID>
        </GetAdditionalTrainDispatchListItems>
        </soap:Body>
        </soap:Envelope>

如果我将参数设置为这样的数组,我将收到没有数据的响应

 var args2 = [
{
    'attributes' : {'xmlns': "http://tempuri.org/"},
    'from':[ Date1],
    'to':[ enDate ],
    'clientID':[ '0' ]
}]

以参数为数组的传出xml2

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract">
    <soap:Header>
        <tt4tServiceSessionID>d5a4533e-8a15-4e1b-8e37-682de50a60df</tt4tServiceSessionID>
    </soap:Header>
    <soap:Body>
        <tns:GetAdditionalTrainDispatchListItems>
            <xmlns>http://tempuri.org/</xmlns>
            <from>2018-07-29</from>
            <to>2018-08-02T11:02:48+02:00</to>
            <clientID>0</clientID>
        </tns:GetAdditionalTrainDispatchListItems>
    </soap:Body>
</soap:Envelope>

如何正确格式化我的数组?

0 个答案:

没有答案