node.js - 如何在 node-soap 中使用派生类型

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

我正在使用 Node Soap https://github.com/vpulim/node-soap发送 SOAP 请求并解析答案。

现在我得到了一个具有派生类型的服务 <searchedAddress xsi:type="PersonAddressDescription"> .

我如何指定 xsi:type="PersonAddressDescription"在我的请求中?

我就是这样做的

  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)
  })
})

请求应该是这样的:

<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>

最佳答案

尝试向您请求的 Node 添加属性。来自 here

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

关于node.js - 如何在 node-soap 中使用派生类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43594158/

相关文章:

Javascript 正则表达式替换捕获

javascript - 如何跟踪来自 Node 的发布请求,请求者是否收到数据

web-services - RPC 伪装成 REST 是个坏主意吗?

iphone - REST 与 SOAP 对于大量安全数据的比较

Delphi Win32 从 ASP.NET 服务接收数据表

Node.js 静态文件服务器逻辑(使用 Connect 中间件)

javascript - 使用 Node.js 删除文本文件的前 15k 行

php - SOAP 请求中的 ns1 和 tem 不匹配会影响请求吗?

c# - 加载\查询大型序列化对象

web-services - 在具有依赖关系的 Scala 代码中调用外部服务