package service.cilent; import java.util.Iterator; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNamespace; import org.apache.axiom.soap.SOAP11Constants; import org.apache.axis2.Constants; import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.Options; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; public class JavaServicesClient { private static EndpointReference targetEPR = new EndpointReference("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx"); @SuppressWarnings("unchecked") public void getResult() throws Exception { ServiceClient sender = new ServiceClient(); sender.setOptions(buildOptions()); //得到axis2定义的xml文件格式 OMElement result = sender.sendReceive(buildParam()); //将axis2的xml格式转换为dom的为XML格式 Document doc = DocumentHelper.parseText(result.toString()); //获取根节点 Element rootElt = doc.getRootElement(); // 获取根节点下的getWeatherbyCityNameResult子节点 Iterator iter = rootElt.elementIterator("getWeatherbyCityNameResult"); while(iter.hasNext()){ Element recordEle = (Element) iter.next(); // 获取子节点getWeatherbyCityNameResult下的子节点string Iterator iters = recordEle.elementIterator("string"); while(iters.hasNext()){ Element itemEle = (Element) iters.next(); //输出string的值 System.out.println(itemEle.getTextTrim()); } } } private static OMElement buildParam() { OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/", ""); OMElement data = fac.createOMElement("getWeatherbyCityName", omNs); OMElement inner = fac.createOMElement("theCityName", omNs); inner.setText("深圳"); data.addChild(inner); return data; } private static Options buildOptions() { Options options = new Options(); options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI); options.setAction("http://WebXml.com.cn/getWeatherbyCityName"); options.setTo(targetEPR); // options.setProperty 如果不是通过代理上网,此句可省 // options.setProperty(HTTPConstants.PROXY, buildProxy()); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); return options; } /** * 本机采用代理服务器上网时,需要设置代理 * * @return */ public static ProxyProperties buildProxy() { ProxyProperties proxyProperties = new ProxyProperties(); proxyProperties.setProxyName("代理名称"); proxyProperties.setProxyPort(8080); return proxyProperties; } public static void main(String[] args) throws Exception { JavaServicesClient s = new JavaServicesClient(); s.getResult(); } }
相关推荐
使用Java+Axis2调用Web Services 网络接口,代码中列举4个例子可以查看,有详细注释提供参考。
本案例实现使用Axis2生成.arr包发布WebService服务,并使用Axis2生成客户端代码方式调用WebService
<groupId>org.apache.axis2 <artifactId>axis2 <version>1.6.2 <groupId>org.apache.axis2 <artifactId>axis2-adb <version>1.6.2 <groupId>org.apache.axis2 ...
axis2客户端调用axis1服务接口 调用方式 使用RPC方式调用WebService,为了防止冲突可以增加 // 与weblogic的lib冲突配置 System.setProperty("javax.xml.stream.XMLInputFactory", ...
用框架cxf调用axis2提供的接口服务的一个简单例子,
java基于Axis2调用C#开发的web service获取xml结果
axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例
使用Axis发补调用服务。对于初学者用帮助!
axis2客户端,调用带ntlm认证的web service的代码例子和所需jar和java
AXIS2客户端调用实例 AXIS2客户端调用实例 AXIS2客户端调用实例 AXIS2客户端调用实例
包括axis2程序包官方下载地址(有点大,没法上传)安装及配置设置,并又客户端代码示例(本人项目中的代码截取)
Axis2调用SAP Webservice源码 使用Axis2 org.apache.axis2.eclipse.codegen.plugin_1.6.2.jar插件生成本地Java Proxy同事生成同步和异步调用测试用例 更重要的是配备详细文档,实乃Java与SAP集成是宝典!
基于 Apache Axis2 将上述类的方法对外提供 Web 服务,生成 WSDL 文件,以及调用 服务 2019-12-23根据全网的教程搭建最详细的教程 源码太大上传不了,但是教程内容十分详细,跟着我的教程一步一步就可以搭建起来,...
axis2 调用实例axis2 调用实例axis2 调用实例
axis2 开发 axis webservice web 服务
axis2客户端调用工程代码
axis2客户端调用服务端,带用户身份认证
使用myeclipse8.5安装axis2插件,工程主要是通过server端类生成服务,生成客户端。 1、使用服务端类com.Hello.java,com.Other.java生成wsdl、aar文件【aar文件通过axis2插件的Axis2 service archiver生成】【wsdl...
axis2调用WCF,包含client、service, java包含对应的的jar包。
用axis2调用JBOSS下的EJB代码