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

时间:2014-10-03 16:36:26

标签: node.js web-services soap exacttarget

我正在尝试使用node-soap包调用Create方法将名为TriggeredSend的{​​{1}}类型对象传递给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>

这给了我这个(没有var soap = require('soap') soap.createClient(url, function(err, client){ client.Create({ Objects: { TriggeredSendDefinition: { CustomerKey: 'abc' } }, function(err, response) {}) }); }); ):

xsi:type

如何为<ns0:CreateRequest> <ns0:Objects> <ns0:TriggeredSendDefinition> <ns0:CustomerKey>abc</ns0:CustomerKey> </ns0:TriggeredSendDefinition> </ns0:Objects> </ns0:CreateRequest> 元素指定TriggeredSend类型?

1 个答案:

答案 0 :(得分:3)

您可以添加一个特殊的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) {})
    });
});

产生:

<ns0:CreateRequest>
   <ns0:Objects xsi:type="ns0:TriggeredSend">
      <ns0:TriggeredSendDefinition>
         <ns0:CustomerKey>abc</ns0:CustomerKey>
      </ns0:TriggeredSendDefinition>
   </ns0:Objects>
</ns0:CreateRequest>