1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| public class JaxWsDispatchClient {
public static void main(String[] args) throws Exception{
URL wsdlLocation = null;
try {
//wsdlLocation = new URL("http://localhost:8000/test?wsdl"); // cxf
wsdlLocation = new URL("http://localhost:8080/transcodeProject?wsdl"); // cxf
} catch (MalformedURLException e) {
e.printStackTrace();
}
//QName serviceName = new QName("http://oca/", "IService");
QName serviceName = new QName("http://transcode.myorg/", "TheTranscodeService");
//QName portName = new QName("http://oca/", "IServicePort");
QName portName = new QName("http://transcode.myorg/", "TheTranscodePort");
// Service service = Service.create(wsdlLocation, serviceName);
Service service = Service.create(serviceName);
//String endpointAddress ="http://localhost:8000/test";
String endpointAddress ="http://localhost:8080/transcodeProject";
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();
// Create SOAPMessage Request
SOAPMessage request = factory.createMessage();
SOAPBody body = request.getSOAPBody();
//QName ns = new QName("http://oca/", "sayHi", "oca");
QName ns = new QName("http://transcode.myorg/", "doTranscode", "transcode");
SOAPBodyElement el = body.addBodyElement(ns);
SOAPElement message = el.addChildElement("arg0");
message.addTextNode("hello");
/*
* Invoke
*/
SOAPMessage reply = dispatch.invoke(request);
//QName responseName =new QName("http://oca/", "sayHiResponse");
QName responseName =new QName("http://transcode.myorg/", "doTranscodeResponse");
body = reply.getSOAPBody();
Element elReturn = (Element)body.getElementsByTagName("return").item(0);
String value =elReturn.getTextContent();
System.out.println(">"+value);
System.out.println("Completed");
}
} |
Partager