Tuesday, 27 August 2013

Java Jax-ws Dynamic Client - response is null?

Java Jax-ws Dynamic Client - response is null?

I am currently doing a jax-ws client that can connect to any web service
wsdl and perform some actions. However for some reason ( i don't know why
) in my response i am getting null?? although i do not get any errors?
WSDL location: WSDL location
Code:

URL wsdlLocation = new
URL("http://www.dataaccess.com/webservicesserver/textcasing.wso?WSDL");
// Qnames for service as defined in wsdl.
QName sName = new
QName("http://www.dataaccess.com/webservicesserver/",
"TextCasing");//"TextCasting"
// Create a dynamic Service instance
Service service = Service.create(wsdlLocation, sName);
//QName for Port As defined in wsdl.
QName portName = new QName("http://dataaccess.com", "TextCasingSoap");
//Endpoint Address // targetNameSpace
String endpointAddress =
"http://dataaccess.com/webservicesserver/textcasing.wso";
// Add a port to the Service
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,
endpointAddress);
//Create a dispatch instance
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName,
SOAPMessage.class, Service.Mode.MESSAGE);
// Use Dispatch as BindingProvider
BindingProvider bp = (BindingProvider) dispatch;
// Optionally Configure RequestContext to send SOAPAction HTTP Header
Map<String, Object> rc = bp.getRequestContext();
//Ask Requestcontext to use SoapAction
rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
//Add SoapAction to request context
//operation name
rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, "InvertStringCase");
// Obtain a preconfigured SAAJ MessageFactory
MessageFactory factory = ((SOAPBinding)
bp.getBinding()).getMessageFactory();
// Create SOAPMessage Request
SOAPMessage request = factory.createMessage();
// Request Header
SOAPHeader header = request.getSOAPHeader();
// Request Body
SOAPBody body = request.getSOAPBody();
// Compose the soap:Body payload (Request Method)
QName payloadName = new
QName("http://www.dataaccess.com/webservicesserver/",
"InvertStringCase");
//message request
SOAPBodyElement payload = body.addBodyElement(payloadName);
SOAPElement message = payload.addChildElement("sAString");
message.addTextNode("HelloWorld");
// Invoke the endpoint synchronously
SOAPMessage reply = null;
try {
//Invoke Endpoint Operation and read response
reply = dispatch.invoke(request);
} catch (WebServiceException wse){
wse.printStackTrace();
}
// process the reply
body = reply.getSOAPBody();
//message response (Response Method)
QName responseName = new
QName("http://www.dataaccess.com/webservicesserver/",
"InvertStringCaseResponse");
System.out.println(responseName);
//SOAPBodyElement
Object bodyElement = body.getChildElements(responseName).next();
System.out.println(bodyElement);
SOAPBodyElement soapbody = (SOAPBodyElement)bodyElement;
System.out.println(soapbody);
String msg = soapbody.getValue();
System.out.println(msg);
Any help appreciated. Thank you

No comments:

Post a Comment