本文介绍了使用JAX WS连接到SOAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用JAXWS在Java中构建一个肥皂客户端.我在Google上进行了搜索,但未找到任何相关信息.这是我尝试过的:
I want to build a soap client in java using JAXWS. I searched on google but didn't find any relevant information. Here is what I have tried:
QName serviceName = new QName("urn:Site", "Site");
QName portName = new QName("urn:Site", "Server_HandlerPort");
String endpointAddress = "http://myhost/url/soap";
Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
BindingProvider bp = (BindingProvider) dispatch;
MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();
SOAPMessage request = factory.createMessage();
SOAPHeader header = request.getSOAPHeader();
SOAPBody body = request.getSOAPBody();
QName payloadName = new QName("session");
SOAPBodyElement payload = body.addBodyElement(payloadName);
SOAPMessage reply = null;
try {
reply = dispatch.invoke(request);
} catch (WebServiceException wse){
wse.printStackTrace();
}
body = reply.getSOAPBody();
QName responseName = new QName("urn:site","sessionResponse");
SOAPBodyElement bodyElement = (SOAPBodyElement) body.getChildElements(responseName).next();
System.out.println(bodyElement.getValue());
这不起作用.这总是返回null
我不确定为什么?谁可以帮我这个事?有什么例子吗?做这样的事情?
This do not work. This always returns null
I'm not sure why? Can anyone help me on this? Any example? for doing such thing?
推荐答案
JAX-WS允许您使用wsimport从Web服务的WSDL生成客户端.这将使客户端代码更加简单.这是一个示例教程
JAX-WS allows you to generate a client from the web service's WSDL using wsimport.This will make the client code much simpler.Here's a sample tutorial
这篇关于使用JAX WS连接到SOAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!