我正在申请中希望我需要调用soap web服务。为此我正在使用SAAJ。为了测试我做了下面的方法来调用服务。此服务返回一个接收为输入的字符串。我的问题是服务被调用但它没有接收输入参数。任何人都可以告诉我如何解决这个问题吗? 2.我还有另一个问题,如何调用具有对象作为输入的服务? 3. SAAJ是创建远程客户到invoque肥皂服务的最佳解决方案吗? 谢谢
public void invokeExtractMetadata(Service service,String path) throws Exception {
System.out.println("invoke");
QName serviceName = new QName(service.namespace, service.serviceName);
QName portName = new QName(service.namespace, service.portType);
String endpointAddress =service.endPointAddress;
javax.xml.ws.Service myService = javax.xml.ws.Service.create(serviceName);
myService.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
Dispatch<SOAPMessage> dispatch = myService.createDispatch(portName, SOAPMessage.class, javax.xml.ws.Service.Mode.MESSAGE);
BindingProvider bp = (BindingProvider) dispatch; //Use Dispatch as BindingProvider
MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();
SOAPMessage request = factory.createMessage();
// Request Header
SOAPHeader header = request.getSOAPHeader();
// Request Body
SOAPBody body = request.getSOAPBody();
// Compose the soap:Body payload
QName payloadName = new QName(service.namespace,service.inMsgTag );
SOAPBodyElement payload = body.addBodyElement(payloadName);
QName name = new QName("pathT");
SOAPElement message = payload.addChildElement(name);
message.addTextNode(path);
SOAPMessage reply = null;
//Invoke Endpoint Operation and read response
reply = dispatch.invoke(request);
//process the reply
body = reply.getSOAPBody();
QName responseName = new QName(service.namespace, service.outMsgTag);
SOAPBodyElement bodyElement = (SOAPBodyElement)body.getChildElements(responseName).next();
QName elementName = new QName("", "return");
Iterator t =bodyElement.getChildElements(elementName);
System.out.println("tt");
while(t.hasNext()){
SOAPBodyElement bodyElementTest = (SOAPBodyElement)t.next();
String valeur = bodyElementTest.getValue();
System.out.println("valeur"+valeur);
}
}