node-soap客户端中数组字段的命名空间(Node.js)

问题描述 投票:5回答:2

如何配置node-soap客户端不仅为对象设置数组的命名空间?

我的'sendPatient'方法的参数。

params = {
        patientCard: {
          patient: {
            firstName: 'test',
            lastName: 'test'
          },
          identifiers:
            {
              code: "123456789",
              codeType: 1
            }
        }
      };
client.sendPatient(params, ...)

node-soap produce:

<soap:Envelope                                                     
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"           
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            
  xmlns:tns="http://xxx/patient/api/"     
  xmlns:bi="http://xxx/base/info/build/">              
  <soap:Header></soap:Header>                                      
  <soap:Body>                                                      
    <tns:sendPatient                                               
      xmlns:tns="http://xxx/patient/api/" 
      xmlns="http://xxx/patient/api/">    
      <tns:patientCard>                                            
        <ns1:patient                                               
          xmlns:ns1="http://xxx/patient/">
          <ns1:firstName>test</ns1:firstName>
          <ns1:lastName>test</ns1:lastName>                      
        </ns1:patient>                                             
        <ns1:identifiers                                           
          xmlns:ns1="http://xxx/patient/">
          <ns1:code>123456789</ns1:code>                         
          <ns1:codeType>1</ns1:codeType>                           
        </ns1:identifiers>                                         
      </tns:patientCard>                                           
    </tns:sendPatient>                                             
  </soap:Body>                                                     
</soap:Envelope>

它是工作的,但我需要发送数组的标识符,而不是只有一个,所以当我把数组

params = {
        patientCard: {
          patient: {
            firstName: 'test',
            lastName: 'test'
          },
          identifiers: [
            {
              code: "123456789",
              codeType: 1
            }, {
              code: "987654321",
              codeType: 2
            }
          ]
        }
      };

node-soap产生。

<soap:Envelope                                                     
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"           
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            
  xmlns:tns="http://xxx/patient/api/"     
  xmlns:bi="http://xxx/base/info/build/">              
  <soap:Header></soap:Header>                                      
  <soap:Body>                                                      
    <tns:sendPatient                                               
      xmlns:tns="http://xxx/patient/api/" 
      xmlns="http://xxx/patient/api/">    
      <tns:patientCard>                                            
        <ns1:patient                                               
          xmlns:ns1="http://xxx/patient/">
          <ns1:firstName>test</ns1:firstName>                                     
          <ns1:lastName>test</ns1:lastName>                
        </ns1:patient>                                             
        <ns1:identifiers>                                          
          <ns1:code>00100180035</ns1:code>                         
          <ns1:codeType>1</ns1:codeType>                           
        </ns1:identifiers>                                         
        <ns1:identifiers>                                          
          <ns1:code>00100180035</ns1:code>                         
          <ns1:codeType>1</ns1:codeType>                           
        </ns1:identifiers>                                         
      </tns:patientCard>                                           
    </tns:sendPatient>                                             
  </soap:Body>                                                     
</soap:Envelope>                                                   

我从服务器上收到错误信息 <ns1:identifiers> 部分

`[com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "ns1" at [row,col {unknown-source}]: [17,25]]`

我做错了什么?我可以以某种方式添加 xmlns:ns1="http://xxx/patient/"<soap:Envelope> 标签或配置node-soap为数组也添加它(不仅仅是简单的对象)?

xml node.js soap wsdl node-soap
2个回答
14
投票

发布临时解决方案 在Github上

在createClient补丁之后的wsdl定义。

soap.createClient(wsdl, options, function(err, client) {
      client.wsdl.definitions.xmlns.ns1 = 'http://xxx/patient/'
      client.wsdl.xmlnsInEnvelope = client.wsdl._xmlnsMap()

      //works now
      client.sendPatient(...)
});

0
投票

在typScript中,你可以访问私有的wsdl为 Swarthy 注释,但直接追加命名空间。

client['wsdl'].xmlnsInEnvelope += 'xmlns:ns1="http://xxx/patient/"';
client['wsdl']._xmlnsMap();
© www.soinside.com 2019 - 2024. All rights reserved.