如何使用jax-ws APIs 实现webservice client

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自动生成代码

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问