I’ve generated my web service from WSDL in Netbeans 7.1. For security concerns, I can’t show it, but you can safely assume that it’s ok, It’s been production tested.
I can call the web-service ok. If I make the function return and then dump it, it even returns the correct values. What is wrong though, it never receives any parameters from the SOAP call. This is the way I invoke it in the index.jsp:
try {
Soap.ServiceService service = new Soap.ServiceService();
javax.xml.namespace.QName portQName = new javax.xml.namespace.QName("http://external.example.com/", "ServicePort");
String req = "<getTimestampCount xmlns=\"http://external.example.com/\"><msisdn>656</msisdn></getTimestampCount>";
javax.xml.ws.Dispatch<javax.xml.transform.Source> sourceDispatch = null;
sourceDispatch = service.createDispatch(portQName, javax.xml.transform.Source.class, javax.xml.ws.Service.Mode.PAYLOAD);
javax.xml.transform.Source result = sourceDispatch.invoke(new javax.xml.transform.stream.StreamSource(new java.io.StringReader(req)));
javax.xml.transform.TransformerFactory factory = javax.xml.transform.TransformerFactory.newInstance();
javax.xml.transform.Transformer transformer = factory.newTransformer();
java.io.StringWriter writer = new java.io.StringWriter();
javax.xml.transform.Result stringOut = new javax.xml.transform.stream.StreamResult(writer);
transformer.transform(result, stringOut);
writer.close();
out.print(writer.toString());
} catch (Exception ex) {
out.print(ex.getMessage());
}
And this is the function that returns the result:
public long getTimestampCount(java.lang.String msisdn) throws ParameterException, UnknownException_Exception {
//TODO implement this method
System.out.println(msisdn);
throw new UnsupportedOperationException("Not implemented yet.");
}
The printing always produces null. I can’t for the life of me figure out why it’s working, finding the right function, but not passing on the values.
Also, I’ve tested it with this code, and the values returned are correct:
try {
Soap.ServiceService service = new Soap.ServiceService();
Soap.Service port = service.ServicePort();
// TODO initialize WS operation arguments here
java.lang.String msisdn = "5";
// TODO process result here
long result = port.getTimestampCount(msisdn);
out.println("Result = "+result);
} catch (Exception ex) {
out.println(ex.getMessage());
// TODO handle custom exceptions here
}
as expected, this returns a value of 5. This would do fine if I wanted to generate the SOAP response by myself, but I would prefer to receive the response, like the first function does – as SOAP.
Anything else I should post to make this easier? If so, say it, and I’ll try to provide everything needed.
I’ve since solved the problem with these webservices, but I still have no Idea what was wrong with this code.
What I ended up doing, was using the standard syntax, like in the last piece of code. That works perfecty.