Skip to content

WSDL with separate namespace for operation and parameters not handled correctly #1441

@celsowm

Description

@celsowm

The node-soap library doesn't correctly handle WSDLs where the operation wrapper uses a different namespace than its parameters. This is the case with the Brazilian court system (CNJ) WSDLs like TJRJ (Tribunal de Justiça do Rio de Janeiro).

Example WSDL: https://wwwh12.tjrj.jus.br/hMNI/Servico.svc?wsdl

The WSDL defines:

Operation namespace:
Parameter types namespace:
Current behavior: When calling consultarProcesso with { idConsultante: "xxx", senhaConsultante: "xxx", numeroProcesso: "xxx" }, the library generates:

<consultarProcesso xmlns="http://www.cnj.jus.br/servico-intercomunicacao-2.2.2/">
  <idConsultante>xxx</idConsultante>
  <senhaConsultante>xxx</senhaConsultante>
  <numeroProcesso>xxx</numeroProcesso>
</consultarProcesso>

But the server expects:

<ns2:consultarProcesso xmlns:ns1="http://www.cnj.jus.br/tipos-servico-intercomunicacao-2.2.2" xmlns:ns2="http://www.cnj.jus.br/servico-intercomunicacao-2.2.2/">
  <ns1:idConsultante>xxx</ns1:idConsultante>
  <ns1:senhaConsultante>xxx</ns1:senhaConsultante>
  <ns1:numeroProcesso>xxx</ns1:numeroProcesso>
</ns2:consultarProcesso>

Steps to reproduce:

import * as soap from "soap";
const wsdl = "https://wwwh12.tjrj.jus.br/hMNI/Servico.svc?wsdl";
const client = await soap.createClientAsync(wsdl);

const args = {
  idConsultante: "your-id-here",
  senhaConsultante: "your-password-here",
  numeroProcesso: "00000102320258190209",
  incluirCabecalho: true
};

const result = await new Promise((resolve, reject) => {
  client.consultarProcesso(args, function(err, result) {
    if (err) reject(err);
    else resolve(result);
  });
});

Note: The server will return an authentication error with fake credentials, but the XML structure will be wrong - the parameters will be missing the ns1: prefix.

Expected behavior: The library should automatically handle WSDLs where the operation element uses a different namespace than its child parameters, or provide a way to specify the namespace prefix for parameters.

Workaround: Using postProcess to manually add namespace prefixes:

const result = await new Promise((resolve, reject) => {
  client.consultarProcesso(args, function(err, result) {
    if (err) reject(err);
    else resolve(result);
  }, {
    postProcess: (xml: string) => {
      let newXml = xml.replace(
        '<soap:Envelope',
        '<soap:Envelope xmlns:ns1="http://www.cnj.jus.br/tipos-servico-intercomunicacao-2.2.2" xmlns:ns2="http://www.cnj.jus.br/servico-intercomunicacao-2.2.2/"'
      );
      
      newXml = newXml.replace(/<consultarProcesso /g, '<ns2:consultarProcesso ');
      newXml = newXml.replace(/<\/consultarProcesso>/g, '</ns2:consultarProcesso>');
      
      newXml = newXml.replace(/<idConsultante>/g, '<ns1:idConsultante>');
      newXml = newXml.replace(/<\/idConsultante>/g, '</ns1:idConsultante>');
      newXml = newXml.replace(/<senhaConsultante>/g, '<ns1:senhaConsultante>');
      newXml = newXml.replace(/<\/senhaConsultante>/g, '</ns1:senhaConsultante>');
      newXml = newXml.replace(/<numeroProcesso>/g, '<ns1:numeroProcesso>');
      newXml = newXml.replace(/<\/numeroProcesso>/g, '</ns1:numeroProcesso>');
      newXml = newXml.replace(/<incluirCabecalho>/g, '<ns1:incluirCabecalho>');
      newXml = newXml.replace(/<\/incluirCabecalho>/g, '</ns1:incluirCabecalho>');
      
      return newXml;
    }
  });
});

Environment:

node-soap version: 1.6.4
Node.js version: 20.x

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions