格式化SOAP请求信封

我正尝试使用节点js格式化SOAP请求信封,应该如下所示:

<?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://xml.apache.org/xml-soap" xmlns:enc="http://www.w3.org/2003/05/soap-encoding"> <env:Body> <env:getStaffRecords env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> <params xsi:type="ns1:Map"> <item> <key xsi:type="xsd:string">limit</key> <value xsi:type="xsd:string">3</value> </item> <item> <key xsi:type="xsd:string">page</key> <value xsi:type="xsd:string">1</value> </item> </params> </env:getStaffRecords> </env:Body> </env:Envelope> 

我提到: https : //loopback.io/doc/en/lb3/Strong-soap.html#xml-attributes

但是,我无法得到预期的产出。 下面是我的演示代码和输出。

 "use strict"; var soap = require('strong-soap').soap; var WSDL = soap.wsdl; var url = "https://testrequest.ch/api/soap/whoswho/wsdl"; // var args = null; // var args = {limit: '10', page: '1'}; var args = { params: { $attributes: { $xsiType: "ns1:Map", }, item: [{ key: { $attributes: { $xsiType: "xsd:string", }, $value: "limit" }, value: { $attributes: { $xsiType: "xsd:string", }, $value: "3" } }, { key: { $attributes: { $xsiType: "xsd:string", }, $value: "page" }, value: { $attributes: { $xsiType: "xsd:string", }, $value: "1" } }] }}; var wsdlOptions = { }; soap.createClient(url, wsdlOptions, function(err, client){ client.setSecurity(new soap.BasicAuthSecurity("api_noob", "randompassword")); client.getStaffRecords(args, function(err, result, envelope){ //console.log(envelope); //console.log('Result: \n' + JSON.stringify(result)); console.log('last request: ', client.lastRequest); }) }); 

其中生成请求信封:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header/> <soap:Body> <ns1:getStaffRecords xmlns:ns1="https://testrequest.ch/api/whoswho/"> <params xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="" xsi:type="ns2:Map"> <item> <key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" " xsi:type="xsd:string">limit</key> <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd ="" xsi:type="xsd:string">3</value> </item> <item> <key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" " xsi:type="xsd:string">page</key> <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd ="" xsi:type="xsd:string">1</value> </item> </params> </ns1:getStaffRecords> </soap:Body> </soap:Envelope>