步骤一:下载Axis2,http://axis.apache.org/axis2/java/core/download.cgi,选择Binary Distribution zip
步骤二:新建一个java工程,并把下载的Axis2中的lib里的jar包都引入进来
步骤三:新建class代码如下:
package cn.test;
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.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class TestZip
{
private static EndpointReference targetEPR = new EndpointReference(
"http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx");
public void getResult() throws Exception
{
ServiceClient sender = new ServiceClient();
sender.setOptions(buildOptions());
OMElement result = sender.sendReceive(buildParam());
System.out.println(result);
}
private static OMElement buildParam()
{
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/", "");
OMElement data = fac.createOMElement("getAddressByZipCode", omNs);
OMElement inner = fac.createOMElement("theZipCode", omNs);
OMElement inner1 = fac.createOMElement("userID", omNs);
inner.setText("425900");
inner1.setText("");
data.addChild(inner);
data.addChild(inner1);
return data;
}
private static Options buildOptions()
{
Options options = new Options();
options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
options.setAction("http://WebXml.com.cn/getAddressByZipCode");
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
{
TestZip s = new TestZip();
s.getResult();
}
}
输出是:<getAddressByZipCodeResponse xmlns="http://WebXml.com.cn/"><getAddressByZipCodeResult><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet"><xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="ZipInfo"><xs:complexType><xs:sequence><xs:element name="PROVINCE" type="xs:string" minOccurs="0" /><xs:element name="CITY" type="xs:string" minOccurs="0" /><xs:element name="ADDRESS" type="xs:string" minOccurs="0" /><xs:element name="ZIP" type="xs:string" minOccurs="0" /></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema><diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"><NewDataSet xmlns=""><ZipInfo diffgr:id="ZipInfo1" msdata:rowOrder="0"><PROVINCE>湖南</PROVINCE><CITY>东安县</CITY><ADDRESS>白牙市镇</ADDRESS><ZIP>425900</ZIP></ZipInfo><ZipInfo diffgr:id="ZipInfo2" msdata:rowOrder="1"><PROVINCE>湖南</PROVINCE><CITY>东安县</CITY><ADDRESS>茶源乡</ADDRESS><ZIP>425900</ZIP></ZipInfo><ZipInfo diffgr:id="ZipInfo3" msdata:rowOrder="2"><PROVINCE>湖南</PROVINCE><CITY>湖南</CITY><ADDRESS>东安县</ADDRESS><ZIP>425900</ZIP></ZipInfo><ZipInfo diffgr:id="ZipInfo4" msdata:rowOrder="3"><PROVINCE>湖南</PROVINCE><CITY>东安县</CITY><ADDRESS>荷池乡</ADDRESS><ZIP>425900</ZIP></ZipInfo><ZipInfo diffgr:id="ZipInfo5" msdata:rowOrder="4"><PROVINCE>湖南</PROVINCE><CITY>东安县</CITY><ADDRESS>水岭乡</ADDRESS><ZIP>425900</ZIP></ZipInfo><ZipInfo diffgr:id="ZipInfo6" msdata:rowOrder="5"><PROVINCE>湖南</PROVINCE><CITY>东安县</CITY><ADDRESS>县城(白牙市镇)</ADDRESS><ZIP>425900</ZIP></ZipInfo></NewDataSet></diffgr:diffgram></getAddressByZipCodeResult></getAddressByZipCodeResponse>
分享到:
相关推荐
本案例实现使用Axis2生成.arr包发布WebService服务,并使用Axis2生成客户端代码方式调用WebService
Java通过Axis2调用SAP的Webservice 生成Java Proxy
Axis2调用SAP Webservice源码 使用Axis2 org.apache.axis2.eclipse.codegen.plugin_1.6.2.jar插件生成本地Java Proxy同事生成同步和异步调用测试用例 更重要的是配备详细文档,实乃Java与SAP集成是宝典!
<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 ...
使用Java+Axis2调用Web Services 网络接口,代码中列举4个例子可以查看,有详细注释提供参考。
axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例
java axis客户端调用webservice,可应用于ofbiz框架。 解决网络上共享代码两次调用后会出现timeout的BUG
Android 利用axis2 调用webservice 包含j2ee服务端代码和Android客户端代码 代码实现包含 List,map ,对象传递
axis2客户端调用axis1服务接口 调用方式 使用RPC方式调用WebService,为了防止冲突可以增加 // 与weblogic的lib冲突配置 System.setProperty("javax.xml.stream.XMLInputFactory", ...
axis2+Spring提供WebService服务,有调用方法类。
Java Axis 直接调用webservice 接口工具类, 无需根据wsdl编译客户端,需要axis相关包,测试使用axis 1.4, 附demo引入axis包后直接可以测试;
用AXIS2作为客户端调用webService的demo:亲测可用,eclipse工程java项目包含完整代码和完整jar包, 只要用eclipse导入项目即可,运行控制台显示success或者false字符串,说明OK。
本方法是用axis1.4技术,实现java客户端调用webservice。已经可实现过可行的,如果不行可加我QQ号302633进行详细解析。
axis2客户端调用webService接口需要用的jar包,在一次调接口中遇到的问题,亲测可用(整理成了比较精简的jar包)
3、测试类或者jsp页面,可以通过2中的客户端类来调用服务 例如: HelloStub helloStub=new HelloStub("http://127.0.0.1:8080/axis2/services/HelloService"); Helloworld helloworld=new Helloworld(); hello...
今天特意将项目中用Axis2集成SSH实现WebService的过程记录下来,一方面做一下笔记,另一方面,方便广大码农朋友,希望能跟大家交流学习。 本文介绍用Axis2集成SSH搭建WebService。会达到的效果: 1.按照传统我们用...
利用eclipse,axis2框架,搭建WebService服务端,以及如何调用接口的教程
axis调用第三方webservice接口所需的jar包,包括axis-1.4.jar,axis-jaxrpc-1.3.jar,axis-jaxrpc-1.4.jar,commons-discovery-0.5.jar,commons-logging-1.2.jar,cxf-rt-databinding-jaxb-3.3.1.jar,javax.mail-...
用AXIS2作为客户端调用webService的demo:本人亲测可用,eclipse工程java项目包含完整代码和完整jar包, 只要用eclipse导入项目即可,运行控制台显示success或者false字符串,说明OK。
描述了axis2如何调用webservice,jar齐全,首先保证webservice的url能正常访问,下载资源后直接运 行com.axis2.test.TestAxis2的main方法即可。 axis2功能十分强大,可接受方法中返回任何类型,比如List, Set,...