5

如何不仅为对象配置数组的节点肥皂客户端集命名空间?

我的“sendPatient”方法的参数:

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

节点肥皂产生:

<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
            }
          ]
        }
      };

节点肥皂产生:

<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 以将其添加到数组中(不仅仅是简单的对象)吗?PS对不起我的英语

4

2 回答 2

16

在 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(...)
});
于 2015-06-10T17:43:41.810 回答
0

在打字稿中,您可以作为Swarthy注释访问私有 wsdl ,但直接附加命名空间:

client['wsdl'].xmlnsInEnvelope += 'xmlns:ns1="http://xxx/patient/"';
client['wsdl']._xmlnsMap();
于 2020-06-11T08:59:52.233 回答