我看到了Working Soap client example。但是,当我为soapbody添加子节点时,它将引发异常。

这是错误:

线程“主”中的异常com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:无法找到前缀ns3的名称空间

这是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");

如何解决。谢谢!!!!

最佳答案

您需要添加一个名称空间声明:

envelope.addNamespaceDeclaration("ns3", "your-namespace");

10-06 13:03