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());
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?