首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

jax-ws 客户端动态访问总结

2012-08-11 
jax-ws 客户端动态访问小结最近研究java6自带的webservice包(jax-ws),一些代码分享下。?public static void

jax-ws 客户端动态访问小结

最近研究java6自带的webservice包(jax-ws),一些代码分享下。

?

public static void procWeb() throws Exception{QName serviceName = new QName("http://WebXml.com.cn/", "qqOnlineWebService");//QName for Port As defined in wsdl.QName portName = new QName("http://WebXml.com.cn/", "qqOnlineWebServiceSoap");////Endpoint AddressString  endpointAddress = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl";//Create a dynamic Service instanceService service = Service.create(serviceName);service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);  //Create a dispatch instanceDispatch<SOAPMessage> dispatch =    service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);// Use Dispatch as BindingProviderBindingProvider bp = (BindingProvider) dispatch;// Optionally Configure RequestContext to send SOAPAction HTTP HeaderMap<String, Object> rc = bp.getRequestContext();rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, "http://WebXml.com.cn/qqCheckOnline");// Obtain a preconfigured SAAJ MessageFactoryMessageFactory factory = ((SOAPBinding)bp.getBinding()).getMessageFactory();// Create SOAPMessage RequestSOAPMessage request = factory.createMessage();// Request BodySOAPBody body = request.getSOAPBody();// Compose the soap:Body payloadQName payloadName =   new QName("http://WebXml.com.cn/", "qqCheckOnline");SOAPBodyElement payload = body.addBodyElement(payloadName); SOAPElement message = payload.addChildElement("qqCode");message.addTextNode("88888");// Invoke the endpoint synchronouslySOAPMessage reply = null;try {//Invoke Endpoint Operation and read responsereply = dispatch.invoke(request);} catch (WebServiceException wse){wse.printStackTrace();}// process the replySOAPBody bodyRes = reply.getSOAPBody();SOAPBodyElement nextSoapBodyElement = (SOAPBodyElement)bodyRes.getChildElements().next();                      SOAPElement soapElement = (SOAPElement)nextSoapBodyElement.getChildElements().next();String strmsg = soapElement.getValue();System.out.println(strmsg);}
?

热点排行