2016-06-06 16 views
0

웹 서비스 클라이언트를 개발 중이며 다음과 같은 코드를 생성합니다.SOAP 메시지 만들기 : NAMESPACE_ERR 이름 공간과 관련하여 잘못된 방식으로 개체를 만들거나 변경하려고 시도했습니다.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:env="Envio_ConsultaSecuencia"> 
    <soapenv:Header/> 
     <soapenv:Body> 
     <env:envio> 
      <env:cabecera> 
       <env:idMensaje>ABCDEFG<env:idMensaje>    
       <env:tipoMensaje>ABCDEFG</env:tipoMensaje> 
      </env:cabecera> 
     </env:envio> 
    </soapenv:Body> 
</soapenv:Envelope> 

제 문제는 cabecera에 접두사 "env"를 삽입하려고 할 때입니다. 이것은 내가 사용하고 코드입니다 : 내가 명명 된 SOAPElement의 접두사 "ENV"를 설정할 수 있습니다 이유

MessageFactory factory = MessageFactory.newInstance(); 
    SOAPMessage message = factory.createMessage(); 
    SOAPPart soapPart = message.getSOAPPart(); 
    SOAPEnvelope envelope = soapPart.getEnvelope(); 
    SOAPHeader header = envelope.getHeader(); 
    SOAPBody body = envelope.getBody(); 


    SOAPElement envio = body.addChildElement("envio"); 
    envio.setPrefix("env"); 


     SOAPElement cabecera = envio.addChildElement("cabecera"); 
     cabecera.setPrefix("env"); 
     (...) 

내가 이해하지 않는다 "envío"나는 cabecera "와 동일한 작업을 수행하기 위해 노력하고있어 때 "이 오류가 있습니다 :

org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces. 

나는 당신의 도움을받을 것입니다. 미리 감사드립니다.

편집 :

나는 오라클의 웹 https://docs.oracle.com/cd/E19340-01/820-6767/aeqfx/index.html

의 해결책을 발견 각각의 아이를 작성하는 올바른 방법은 다음과 같습니다

Name bodyName = envelope.createName("GetLastTradePrice", "m", 
             "http://eztrade.com") 
SOAPBodyElement gltp = body.addBodyElement(bodyName); 

그리고 접두사는 문제없이 삽입됩니다.

그게 전부입니다!

+0

해결책을 찾았습니다. 나는 그 글을 편집한다. –

답변

1

SOAPElement envio 또는 SOAPEnvelope에 네임 스페이스 선언을 추가하십시오.

 SOAPMessage message = factory.createMessage(); 
     SOAPPart soapPart = message.getSOAPPart(); 
     SOAPEnvelope envelope = soapPart.getEnvelope(); 
     //add declaration here 
     envelope.addNamespaceDeclaration("env", "http://som.org"); 
     SOAPHeader header = envelope.getHeader(); 
     SOAPBody body = envelope.getBody(); 


     SOAPElement envio = body.addChildElement("envio"); 
     envio.setPrefix("env"); 
     //explicit declare it here for this element 
     envio.addNamespaceDeclaration("env", "http://som.org"); 
     SOAPElement cabecera = envio.addChildElement("cabecera","env");