相关疑难解决方法(0)

为什么我收到java.lang.NullPointerException而不是soap响应?

我发送以下请求到服务器,当我复制请求并使用SOAPUI它显示正确的响应,

但是当我使用以下代码生成并发送它时,返回

java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)

在第50行,这是

sm.writeTo(out);
Run Code Online (Sandbox Code Playgroud)

码:

SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
SOAPFactory soapFactory = SOAPFactory.newInstance();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();        
SOAPBody body = soapEnvelope.getBody();
header.removeNamespaceDeclaration(header.getPrefix());

soapEnvelope.addNamespaceDeclaration("v9", "ADDRESS OF SERVICE");

Name bodyName;
bodyName = soapFactory.createName("User");

SOAPElement getList = body.addChildElement("User", "v9");

Name childName;

getList.addChildElement("name", "v9").addTextNode("Alex");
getList.addChildElement("surname", "v9").addTextNode("Nicroid");   

message.writeTo(System.out); 

URL endpoint = new URL("ENDPOINT ADDRESS OF SERVER");
SOAPMessage response = connection.call(message, endpoint);

connection.close();

SOAPMessage sm …
Run Code Online (Sandbox Code Playgroud)

java soap soapui soap-client

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

soap ×1

soap-client ×1

soapui ×1