2014-10-03 38 views
0

我試圖調用Create方法將名爲ObjectsTriggeredSend類型對象傳遞給使用node-soap包的ExactTarget SOAP Web服務。如何使用node-soap爲SOAP請求中的元素指定xsi:type

我需要創造的東西,看起來像這樣(請注意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類型爲Objects元素?

回答

2

有一個特殊的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> 
相關問題