4

I saw Working Soap client example . But when i add child node for soapbody it throw an exception.

Here is error:

Exception in thread "main" com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to locate namespace for prefix ns3

Here is code for SOAPrequest:

MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody soapBody = envelope.getBody();
SOAPElement node1 = soapBody.addChildElement("lookupEligibility","ns3");

How to solve it. Thanks!!!!

Community
  • 1
  • 1
sonas sonas
  • 197
  • 1
  • 5
  • 15
  • 2
    soapBody.addChildElement("lookupEligibility","ns3","http://ns3_namespace"); or define ns3 above in your code. – kingAm Feb 20 '14 at 03:50

1 Answers1

5

You need to add a namespace declaration:

envelope.addNamespaceDeclaration("ns3", "your-namespace");
helderdarocha
  • 23,209
  • 4
  • 50
  • 65