String wsdlUrl="http://localhost:8080/springmvc/services/helloWebService?wsdl";
QName serviceName=new QName("http://springmvc.com/","helloWebService");
Service service=Service.create(serviceName);
service.addPort(serviceName, javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING,wsdlUrl);
Dispatch dispatch=service.createDispatch(serviceName,SOAPMessage.class,Service.Mode.MESSAGE);
MessageFactory messageFactory=MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage request=messageFactory.createMessage();
SOAPPart part=request.getSOAPPart();
SOAPEnvelope soapEnvelope=part.getEnvelope();
SOAPHeader header=soapEnvelope.getHeader();
SOAPBody body=soapEnvelope.getBody();
SOAPElement operation=body.addChildElement("hello","nsl","http://springmvc.com/");
SOAPElement value=operation.addChildElement("name");
value.addTextNode("a");
request.saveChanges();
SOAPMessage response=dispatch.invoke(request);
System.out.println(response.getSOAPBody());
这是参考官方文档写的,但并不能成功调用webservice 接口。希望是使用jax-ws APIs代码的方式调用,而不是wsimport自动生成代码