How to use derived types in node-soap

时间:2017-04-24 17:15:55

标签: node.js web-services soap node-soap

I'm using Node Soap https://github.com/vpulim/node-soap to send SOAP requests and parse the answers.

Now I've got a service which has a derived type <searchedAddress xsi:type="PersonAddressDescription">.

How do I specify the xsi:type="PersonAddressDescription" in my request?

This is what I do

  const args = {
    searchedAddress: {
      location: {
        street: 'Karl-Theorstraße 88',
        zip: '34234',
        city: 'Rummelshausen'
      },
      firstName: 'Foo',
      lastName: 'Bar'
    }
  }

soap.createClient(WSDL, wsdlOptions, (err, client) => {
  client.getReport(args, (err, result) => {
    if (err !== null) {
      console.log(client.lastRequest)
      reject(err)
    }
    resolve(result)
  })
})

This is how the request is supposed to look like:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
 <soap:Header/>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <getReportRequest xmlns="http://www.service.com/superservice/v1.00">
      <searchedAddress xsi:type="PersonAddressDescription">
        <location>
          <street>Karl-Theorstraße 88</street>
          <zip>34234</zip>
          <city>Rummelshausen</city>
        </location>
        <firstName>Foo</firstName>
        <lastName>Bar</lastName>
      </searchedAddress>
    </getReportRequest>
  </s:Body>
</s:Envelope>

1 个答案:

答案 0 :(得分:1)

尝试将attributes添加到您请求的节点。来自here

 const args = {
    searchedAddress: {
      attributes: {
        'xsi:type': 'PersonAddressDescription'
        },
      location: {
        street: 'Karl-Theorstraße 88',
        zip: '34234',
        city: 'Rummelshausen'
      },
      firstName: 'Foo',
      lastName: 'Bar'
    }
  }