如何使用 node-soap 为 SOAP 请求中的元素指定 xsi:type

Glo*_*opy 2 soap web-services node.js exacttarget

我正在尝试使用 node-soap 包调用Create传入TriggeredSend名为 ExactTarget SOAP Web 服务的类型化对象的方法。Objects

我需要创建看起来像这样的东西(注意xsi:type="ns0:TriggeredSend"):

<SOAP-ENV:Envelope xmlns:etns="http://exacttarget.com" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns0="http://exacttarget.com/wsdl/partnerAPI" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header>
   </SOAP-ENV:Header>
   <ns1:Body>
      <ns0:CreateRequest>
         <ns0:Objects xsi:type="ns0:TriggeredSend">
            <ns0:TriggeredSendDefinition>
               <ns0:CustomerKey>abc</ns0:CustomerKey>
            </ns0:TriggeredSendDefinition>
         </ns0:Objects>
      </ns0:CreateRequest>
   </ns1:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)

通过下面的代码,我接近了:

var soap = require('soap')

soap.createClient(url, function(err, client){
    client.Create({
        Objects: {
            TriggeredSendDefinition: {
                CustomerKey: 'abc'
            }
        },
        function(err, response) {})
    });
});
Run Code Online (Sandbox Code Playgroud)

这给了我这个(没有xsi:type):

<ns0:CreateRequest>
   <ns0:Objects>
     <ns0:TriggeredSendDefinition>
        <ns0:CustomerKey>abc</ns0:CustomerKey>
     </ns0:TriggeredSendDefinition>
  </ns0:Objects>
</ns0:CreateRequest>
Run Code Online (Sandbox Code Playgroud)

如何指定元素TriggeredSend的类型Objects

Glo*_*opy 5

您可以添加一个特殊attributes节点来指定xsi:type

var soap = require('soap')

soap.createClient(url, function(err, client){
    client.Create({
        Objects: {
            attributes: {
                xsi_type: {
                    type: 'TriggeredSend',
                    xmlns: 'http://exacttarget.com/wsdl/partnerAPI'
                }
            }
            TriggeredSendDefinition: {
                CustomerKey: 'abc'
            }
        },
        function(err, response) {})
    });
});
Run Code Online (Sandbox Code Playgroud)

其产生:

<ns0:CreateRequest>
   <ns0:Objects xsi:type="ns0:TriggeredSend">
      <ns0:TriggeredSendDefinition>
         <ns0:CustomerKey>abc</ns0:CustomerKey>
      </ns0:TriggeredSendDefinition>
   </ns0:Objects>
</ns0:CreateRequest>
Run Code Online (Sandbox Code Playgroud)