步骤一:下载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发布Web服务和生成客户端代码调用服务是一个标准化的过程,涉及到服务的编写、打包、部署以及客户端的代码生成和调用。了解并熟练掌握这一过程,对进行Java Web服务开发至关重要。在实际开发中,...
用AXIS2作为客户端调用webService的demo:本人亲测可用,eclipse工程java项目包含完整代码和完整jar包, 只要用eclipse导入项目即可,运行控制台显示success或者false字符串,说明OK。
标题中的“Java通过Axis调用天气预报的WebService”是指使用Java编程语言,通过Apache Axis库来访问和使用公开的天气预报Web服务。Apache Axis是一个开放源码的SOAP(简单对象访问协议)工具包,它允许开发者创建和...
Java和Axis2是开发Web服务客户端的重要工具,用于调用基于SOAP协议的Web服务。本文将深入探讨如何利用Java和Axis2库来实现这一功能,同时结合提供的代码示例进行详细解析。 首先,Web服务是一种通过网络进行通信的...
本文将深入探讨如何使用Axis2客户端调用WebService接口,并且会特别关注如何精简所需的jar包。 首先,了解Axis2客户端的基本概念是至关重要的。Axis2客户端是用于与远程Web服务交互的工具,它允许开发者通过SOAP...
Axis2调用SAP Webservice源码 使用Axis2 org.apache.axis2.eclipse.codegen.plugin_1.6.2.jar插件生成本地Java Proxy同事生成同步和异步调用测试用例 更重要的是配备详细文档,实乃Java与SAP集成是宝典!
AXIS2远程调用WebService是Java开发者在进行分布式服务交互时常用的一种技术。本文将详细介绍如何使用Eclipse集成开发环境和AXIS2框架创建并调用WebService。首先,我们需要准备以下基础工具: 1. Eclipse IDE:这...
axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例
总结来说,Spring集成Axis2实现Web服务涉及到Spring的IoC容器、服务的创建和发布、以及客户端的调用等多个环节。了解并掌握这些知识点,对于开发高质量的Web服务应用至关重要。在实际项目中,务必确保所有必要的库...
java axis客户端调用webservice,可应用于ofbiz框架。 解决网络上共享代码两次调用后会出现timeout的BUG
通过上述步骤,我们不仅完成了使用MyEclipse 8.5与Axis2插件创建WebService服务的过程,而且还学会了如何从客户端调用这些服务。这种方式极大地简化了分布式系统的开发流程,提高了开发效率。希望本文能够帮助您更好...
在本文档中,我们将详细介绍如何使用Axis2来发布和调用WebService服务。 对于Axis2程序包的下载,可以访问其官方网站:[http://ws.apache.org/axis2/](http://ws.apache.org/axis2/) 进行下载。需要注意的是,由于...
在Java中使用Axis调用Webservice,首先需要引入必要的库文件。这些库通常包括axis.jar、axis-wsdl4j.jar、commons-discovery.jar、commons-logging.jar、jaxrpc.jar和wsdl4j.jar等。这些库包含了处理SOAP消息、解析...
标题“使用axis轻松调用Webservice”涉及到的是在IT领域中如何通过Apache Axis工具来便捷地与Web服务进行交互。Apache Axis是一个开放源代码的Java框架,它允许开发者创建、部署和使用Web服务。这个标题暗示了我们将...
描述了axis2如何调用webservice,jar齐全,首先保证webservice的url能正常访问,下载资源后直接运 行com.axis2.test.TestAxis2的main方法即可。 axis2功能十分强大,可接受方法中返回任何类型,比如List, Set,...
axis2客户端调用axis1服务接口 调用方式 使用RPC方式调用WebService,为了防止冲突可以增加 // 与weblogic的lib冲突配置 System.setProperty("javax.xml.stream.XMLInputFactory", ...
本文将详细介绍如何使用Axis2调用WebService接口,并基于提供的jar包"axis2-1.7.6"进行说明。 **一、Axis2简介** Axis2是Apache软件基金会开发的一个Web服务引擎,它基于SOAP(Simple Object Access Protocol)和WS...
标题中的“axis2+spring webservice”指的是使用Apache Axis2框架与Spring框架集成来开发Web服务。Apache Axis2是Java环境中广泛使用的Web服务引擎,它提供了高性能、灵活且可扩展的架构。Spring框架则是一个全面的...
Web Service是一种常见的通信方式,而Axis2是Apache组织提供的一款强大的Web Service框架,它支持SOAP和RESTful服务。本文将详细介绍如何在Android应用中利用Axis2来调用Web Service。 **一、Android与Web Service...