如何从node.js强肥皂发送SOAP1.2请求?

时间:2019-02-07 19:13:35

标签: node.js soap soapui strong-soap

我正在使用这个库

https://github.com/strongloop/strong-soap#client

发送SOAP1.2请求。

我可以使用SOAPUI发送此邮件(这里省略了api密钥)

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:v1="urn:IQTrack/WebServices/v1">
   <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
       <wsa:To>https://webservices.iqtrack.com/RequesterSync.svc</wsa:To>
   </soap:Header>
   <soap:Body>
      <v1:VerifyApiKey>
         <!--Optional:-->
         <v1:apiKey>API KEY</v1:apiKey>
      </v1:VerifyApiKey>
   </soap:Body>
</soap:Envelope>

然后我回来

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">urn:IQTrack/WebServices/v1/RequesterSync/VerifyApiKeyResponse</a:Action>
   </s:Header>
   <s:Body>
      <VerifyApiKeyResponse xmlns="urn:IQTrack/WebServices/v1">
         <VerifyApiKeyResult>true</VerifyApiKeyResult>
      </VerifyApiKeyResponse>
   </s:Body>
</s:Envelope>

服务

https://webservices.iqtrack.com/
WSDL: https://webservices.iqtrack.com/RequesterSync.svc?wsdl

但是,现在我想用肥皂洗。

"use strict";

var fs = require('fs');
var soap = require('strong-soap').soap;

// wsdl of the web service this client is going to invoke. For local wsdl you can use, url = './wsdls/stockquote.wsdl'
var url = 'https://webservices.iqtrack.com/RequesterSync.svc?wsdl';

fs.readFile('C:/Users/me/source/repos/SOAPTEST/SOAPTEST/SOAP Envelopes/VerifyAPIKey.xml', 'utf-8', function(err, contents) {
    if (err) {
        return console.log(err);
    }
    var contents = contents.toString();

    var requestArgs = {
        apiKey : 'API Key' // omitted here
    };

    var options = {};
    soap.createClient(url, options, function(err, client) {

        //client.addSoapHeader(`<wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">urn:IQTrack/WebServices/v1/RequesterSync/VerifyApiKey</wsa:Action>`);
        client.addSoapHeader("<soap:Header xmlns:wsa=\"http://www.w3.org/2005/08/addressing\"><wsa:To>https://webservices.iqtrack.com/RequesterSync.svc</wsa:To></soap:Header>");

        var method = client['VerifyApiKey'];

        //return console.log(client.getSoapHeaders());

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

但是又回来了

Response Envelope:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action></s:Header><s:Body><s:Fault><s:Code><s:Value>s:Sender</s:Value><s:Subcode><s:Value>a:DestinationUnreachable</s:Value></s:Subcode></s:Code><s:Reason><s:Text xml:lang="en-US">The message with To '' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher.  Check that the sender and receiver's EndpointAddresses agree.</s:Text></s:Reason></s:Fault></s:Body></s:Envelope>
Result:
{"statusCode":500,"body":"<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\"><s:Header><a:Action s:mustUnderstand=\"1\">http://www.w3.org/2005/08/addressing/soap/fault</a:Action></s:Header><s:Body><s:Fault><s:Code><s:Value>s:Sender</s:Value><s:Subcode><s:Value>a:DestinationUnreachable</s:Value></s:Subcode></s:Code><s:Reason><s:Text xml:lang=\"en-US\">The message with To '' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher.  Check that the sender and receiver's EndpointAddresses agree.</s:Text></s:Reason></s:Fault></s:Body></s:Envelope>","headers":{"content-length":"615","content-type":"application/soap+xml; charset=utf-8","server":"Microsoft-IIS/7.5","x-powered-by":"ASP.NET","x-ua-compatible":"IE=9; IE=8; IE=7; IE=EDGE","x-frame-options":"DENY","date":"Thu, 07 Feb 2019 19:06:58 GMT","connection":"close"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"webservices.iqtrack.com","port":443,"hostname":"webservices.iqtrack.com","hash":null,"search":null,"query":null,"pathname":"/RequesterSync.svc","path":"/RequesterSync.svc","href":"https://webservices.iqtrack.com/RequesterSync.svc"},"method":"POST","headers":{"User-Agent":"strong-soap/1.15.0","Accept":"text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8","Accept-Encoding":"none","Accept-Charset":"utf-8","Connection":"close","Host":"webservices.iqtrack.com","Content-Length":510,"Content-Type":"application/soap+xml; charset=utf-8"}}}

如果删除标头,我会在SOAPUI中看到这种情况。但是我在这里添加了标题。

有人知道这个问题是什么吗?

谢谢

0 个答案:

没有答案