【发布时间】:2013-07-25 10:47:34
【问题描述】:
我想在 TCP 服务器和客户端之间使用 SAAJ API 发送和接收 SOAP 消息。通过使用 SOAPMessage 类的方法 writeTo 写入流,我可以轻松地写入 TCP 套接字,但是如何从 TCP 流中读取 SOAP 消息?哪个类/方法可能有用?
【问题讨论】:
我想在 TCP 服务器和客户端之间使用 SAAJ API 发送和接收 SOAP 消息。通过使用 SOAPMessage 类的方法 writeTo 写入流,我可以轻松地写入 TCP 套接字,但是如何从 TCP 流中读取 SOAP 消息?哪个类/方法可能有用?
【问题讨论】:
你可以使用javax.xml.ws.Endpoint,这里是一个例子
@WebServiceProvider
@ServiceMode(Mode.MESSAGE)
public class SOAPServer implements Provider<SOAPMessage> {
public SOAPMessage invoke(SOAPMessage request) {
... process request and create response
return response;
}
public static void main(String[] args) throws Exception {
Endpoint.publish("http://localhost:1111/test", new SOAPServer());
}
}
发送请求
...
URL endpoint = new URL("http://localhost:1111/test");
SOAPMessage response = connection.call(message, endpoint);
...
【讨论】:
通过本指南,他们详细解释了如何使用 SAAJ 在网络上编写、发送和接收 SOAP 消息:
【讨论】: