Java借助axis2发布WebService
Webservice:
1、Xml:
2、WSDL:
Web service描述语言(WSDL)就是这样一个基于XML(标准通用标记语言下的一个子集)的语言,用于描述Web service及其函数、参数和返回值。WSDL既是机器可阅读的,又是人可阅读的,这将是一个很大的好处。
3、soap simple object access protoacl (简单对象访问协议) :
限定了xml的格式
soap 在http(因为有请求体,所以必须是post请求)的基础上传输xml数据
请求和响应的xml 的格式如: <Envelop><body>//....</body></Envelop>
operation name:服务提供的方法
静态方法不能发布为外部服务
运用jkd自带的代码生成访问服务器的客户端代码 E:/wsimort -s . http://test.cm/?wsdl
我们可以把webservice看做是web服务器上的一个应用,web服务器是webservice的一个容器
函数的参数在 http://test.cm/?xsd=1
JAX-WS是指 java api for xml -WebService
//测试 WebService服务的 explorer
Web Service Explorer 可以显示返回的xml格式
targetNamespace 默认为倒置的包名
一、借助axis2发布wenService服务的一种简单实现
第一步:首先要下载开发所需要的jar包
下载:axis2-1.6.2-war.zip: http://www.apache.org/dist//axis/axis2/java/core/1.6.2/
下载完后将axis2.war放至tomcat安装目录下的webapps文件夹下,然后启动tomcat后,在webapps目录下会生成axis2文件夹。
访问http://localhost:8080/axis2/能看到Apache的webservice页面表示axis2运行成功。
第二步:拷贝axis2必要文件到webproject中
将tomcate发布axis2 -> WEB_INF 下的conf、modules和services 拷贝到当前项目(webProject)的WEB-INF下,并且把axis2 -> WEB-INF -> lib 下的jar拷贝到当前项目lib下;

第三步:配置service.xml
在当前项目services/webservice/META-INF(没有该路径需要新建)下新建services.xml,配置对应的类格式如下:
<?xml version="1.0" encoding="UTF-8"?> <serviceGroup> <service name="income" targetNamespace="http://tempuri.org/"> <schema schemaNamespace="http://tempuri.org/"/> <description>axis2 webservice接口</description>
<parameter name="ServiceClass">tempuri.org.IncomeJC</parameter>
<operation name="incomeAdd">
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service> <service name="incomeData" targetNamespace="http://tempuri.org/">
<schema schemaNamespace="http://tempuri.org/"/>
<description> WebServices提供到账数据查询接口</description>
<parameter name="ServiceClass"> tempuri.org.IncomeDataJC</parameter>
<operation name="incomeList">
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service> </serviceGroup>
1、发布多个接口:services.xml修改为
<serviceGroup>
<service name= "xxx" targetNamespace="http://tempuri.org/" >
<schema schemaNamespace ="http://tempuri.org/"/>
<description > WebServices接口1</description >
<parameter name ="ServiceClass">tempuri.org.xxx</parameter >
<operation name ="function">
<messageReceiver mep= "http://www.w3.org/2004/08/wsdl/in-out"
class= "org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation >
</service>
<service name= "yyy" targetNamespace="http://tempuri.org/" >
...
</service>
</serviceGroup>
2、接口方法消息接收形式(具体限定某方法)
1):有接收值没有返回值
<operation name = "function1">
<messageReceiver mep= "http://www.w3.org/2004/08/wsdl/in-only"
class= "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</operation >
2):既有接收值也有返回值
<operation name = "function2">
<messageReceiver mep= "http://www.w3.org/2004/08/wsdl/in-out"
class= "org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation >
第三步:创建类
新建包tempuri.org,在tempuri.org下新建类IncomeJC。
代码如下:
package tempuri.org;
public class IncomeJC {
public String incomeAdd(String xml) {
String success = "0";
try {
ProjectIncomePub incomePub = readProjectIncome(xml);//读取xml数据
if (null != incomePub) {
success = new ProjectIncomeAction().incomeByJC(incomePub);//进一步处理
}
} catch (Exception e) {
//e.printStackTrace();
System.out.println("到账接口异常");
return success;
}
return success;
}
第四步:修改web.xml配置
在WEB-INF目录下修改web.xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!--Axis2 config start-->
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class >
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<!--Axis2 end-->
</web-app>
新建一个客户端的程序中使用:
/***调用网络服务axis调用webservice**/
this.incomeService();
/***********************************/
import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
private void incomeService() {
String xmlStr = "xmlData";//xml格式的参数数据拼成的字符串
String url = "http://127.0.0.1:8080/webProject/services/systemDDLService";
String method="incomeJC";
String webObject = null;
try {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(url);
options.setTo(targetEPR);
/** 在创建QName对象时,QName类的构造方法的第一个参数表示WSDL文件的命名空间名,也就是<wsdl:definitions>元素的targetNamespace属性值,method指定方法名 */
QName opAddEntry = new QName("http://org.tempuri",method);
/** 参数,如果有多个,继续往后面增加即可,不用指定参数的名称*/
Object[] opAddEntryArgs = new Object[] {xmlStr};
// 返回参数类型,这个和axis1有点区别
/**invokeBlocking方法有三个参数, 其中第一个参数的类型是QName对象,表示要调用的方法名;第二个参数表示要调用的WebService方法的参数值,参数类型为Object[]; 第三个参数表示WebService方法的返回值类型的Class对象,参数类型为Class[]。 */
/**注意: 当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{}
如果被调用的WebService方法没有返回值,应使用RPCServiceClient类的invokeRobust方法,
该方法只有两个参数,它们的含义与invokeBlocking方法的前两个参数的含义相同
*/
Class[] classes = new Class[] { String.class };
webObject = (String)serviceClient.invokeBlocking(opAddEntry,opAddEntryArgs, classes)[0];
System.out.println(webObject);
}catch (Exception e) {
e.printStackTrace();
long end = System.currentTimeMillis();
}
}
Java借助axis2发布WebService的更多相关文章
- Java通过Axis2发布WebService
参考文档: http://blog.csdn.net/ghsau/article/details/12714965 http://www.iteye.com/topic/1135747 http:// ...
- WebService学习之旅(七)Axis2发布WebService的几种方式
前面几篇文章中简单的介绍了如何使用Axis2发布WebService及如何使用Axis2实现Web服务的客户端调用,本节將详细介绍Axis2发布WebService的几种方式. 一.使用aar包方式发 ...
- 使用JDK和axis2发布webservice
最近使用webservice进行远程调用一直很火,自从JDK1.6版本发布后,发布一个webservice项目变得更加简单了 笔者由于工作的需要针对JDK和axis2如何发布webservice做过相 ...
- 用AXIS2发布WebService的方法
Axis2+tomcat6.0 实现webService 服务端发布与客户端的调用. 第一步:首先要下载开发所需要的jar包 下载:axis2-1.6.1-war.zip http://www.apa ...
- tomcat 用AXIS2发布WebService 网站的方法
Axis2+tomcat7.0 实现webService 服务端发布与客户端的调用. Aixs2开发webService的方法有很多,在此只介绍一种比较简单的实现方法. 第一步:首先要下载开发所需要的 ...
- Eclipse中Axis2发布WebService
介绍:Axis是apache下一个开源的webservice开发组件. l 开发工具下载: 1. eclipse的Java EE版本.下载地址:http://www.eclipse.org/dow ...
- Rhythmk 一步一步学 JAVA (18) Axis2 创建 WebService
一 > 环境配置 1.下载Axis2: 目前版本为 1.6.2 下载地址: http://axis.apache.org/axis2/java/core/ 下载 axis2-1.6.2-bin. ...
- 微信小程序访问webservice(wsdl)+ axis2发布服务端(Java)
0.主要思路:使用axis2发布webservice服务端,微信小程序作为客户端访问.步骤如下: 1.服务端: 首先微信小程序仅支持访问https的url,且必须是已备案域名.因此前期的服务器端工作需 ...
- spring与axis2整合发布webservice
最近在研究整合spring框架和axis2发布webservice服务,由于本人也才学java不久,为了便于以后的查看,在这里记录下发布过程. 所需的工具包,spring.jar和axis2链接地址为 ...
随机推荐
- ZOJ Problem Set - 1402 Magnificent Meatballs
比较简单的题目,题目大意就是将n个数字围成一个圈,找到一个划分,是的划分左边的数字之和等于右边的数字之和: e.g 10 1 2 2 5,那么可以找到一个划分10 | 1 2 2 5使得两边数字之和都 ...
- 小div布局之卡片堆叠(card-stacking)
前端的页面布局和各种效果真是让人眼花缭乱,公司的设计师恨不得在一个网站上把前端的布局和样式效果都用一遍. 如何实现下面这种布局效果?我给这种布局效果起了个名字,叫做小div布局之卡片堆叠.然后我百度了 ...
- linux全方位掌握一个命令--思路比方法更重要
Linux命令众多,当不清楚一个命令的使用方法时,我们该怎样了解命令的属性和帮助? 1.用type命令了解一个命令的属性 [root@zejin240 testdir]# type cd cd ...
- 自己封装的Windows7 64位旗舰版,微软官网上下载的Windows7原版镜像制作,绝对纯净版
MSDN官网上下载的Windows7 64位 旗舰版原版镜像制作,绝对纯净版,无任何精简,不捆绑任何第三方软件.浏览器插件,不含任何木马.病毒等. 集成: 1.Office2010 2.DirectX ...
- C#基础-out与ref字段
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- 家族/亲戚(relation)
题目描述 若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系. 规定:x和y是亲戚,y和z是亲戚,那么x和z也是亲戚.如果x,y是 ...
- Git合并分支操作
1. 添加自己的文件 git add .; 2. 缓存自己的文件 git stash; 3. 查看状态 git status; 4. 获取别的分支 git pull origin master(分支名 ...
- poj1789--最小生成树(prim)
水题... 题目大意: 用一个7位的字符串代表一个编号,两个编号之间的distance代表这两个编号之间不同字母的个数.一个编号只能由另一个编号“衍生”出来,代价是这两个编号之间相应的distance ...
- 疯狂Android讲义 - 学习笔记(八)
第10章 Service与BroadcastReceiver 10.1 Service简介 Service组件也是可执行的程序,有自己的生命周期,创建.配置Service与创建.配置Activity的 ...
- Ant搭建 一键生成APP技术 平台
1.博客概要 本文详细介绍了当今流行的一键生成APP技术.介绍了这种设计思想的来源,介绍了国内外的研究背景,并介绍了这个技术体系中的一些实现细节,欢迎各路大神们多提意见.一键生成技术,说的通俗点就是, ...