j2ee web service开发(一) 映射数组复杂类型 - 一切从实用出发! - B...
来源:百度文库 编辑:神马文学网 时间:2024/06/13 06:29:34
之所以把数组类型在调用web service中作为参数的实现郑重的记录下来,实在是因为数组在j2ee web service的实现不是一件容易的问题。至少用Jboss的j2ee web service实现时是这样. 好象网上关于web service的比较深入一点的资料比较少,关于j2ee web service的资料就更少了. 这里只记录了符合WS — I BP 标准的SOAP四种消息传递模式中的RPC/Literal消息传递模式。这个请参考书籍《j2ee web service 高级编程》一书。该书也只能是参考了,只是介绍了web service的理论实现及一点jax-rpc 的API,并且还有蛮多印刷错字。虽然jax-rpc API的目标之一就是为了在各种java 的web service实现技术中提供一个便携的手段,然而各种j2ee服务器的web service技术还是有些差别的,这个还是造成了程序不能直接在各种j2ee服务器之间毫无修改的移植。在 apache的axis实现中,数组作为参数传递根本不值一提,借助工具很方面的就可以实现。
但是在jboss中的ws实现中确不是一件便利的事情。因为郁闷了很久,发点牢骚:)具体实现:
作为web service服务实现的类必须实现java.rmi.Remote的接口:
package array;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface CountUser extends Remote {
public int countUser(User[] user) throws RemoteException;
}
具体实现远程接口的类:
package array;
public class CountUserImpl implements CountUser {
public int countUser(User[] user){
for(int i=0;iSystem.out.println("name "+user[i].getName()+" phone "+
user[i].getPhone()+ " birthday "+user[i].getBirthDay());
}
return user.length;
}
}
作为数组参数传递的类:
package array;
import java.util.Date;
public class User {
private String name;
private String phone;
private Date birthDay;
public User() {
}
public User(String name,String phone,Date birthDay){
this.name=name;
this.phone=phone;
this.birthDay=birthDay;
}
public void setName(String name) {
this.name = name;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setBirthDay(Date birthDay) {
this.birthDay = birthDay;
}
public String getName() {
return name;
}
public String getPhone() {
return phone;
}
public Date getBirthDay() {
return birthDay;
}
}
使用Jboss_Home/bin 下的wstools工具生成布署j2ee web service 必须的三个文件,jax-rpc映射文件,web服务描述器文件,以及wsdl文档用于wstools工具的配置文件jboss-config.xml类容如下:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.org/jbossws-tools http://www.jboss.org/jbossws-tools/schema/jbossws-tool_1_0.xsd"
使用 wstools -cp array.CountUser -config jboss-config.xml 命令可以生成布署web服务所需的三个文件。另外还得在web.xml文件中把CountUser接口作为servlet发布
CountUser Servlet
CountUser
array.CountUserImpl
CountUser
/CountUser
CountUser
/services/*
仅仅是这样倒也算很容易了,但是wstools工具并不能在映射文件中正确实现User[]的映射。因此还需要手工添加如下代码以实现User[] 到xml之间的映射。
array.User[]
typeNS:User.Array
complexType
打包成war文件,并且布署。服务端的实现就完成了。打包的war文件下载 使用的Jboss版本4.04
因为篇幅或许还有分类的原因,客户端的实现将记录在下一篇随笔里 如果你想赐教或者讨论,欢迎加入QQ群:30406099
但是在jboss中的ws实现中确不是一件便利的事情。因为郁闷了很久,发点牢骚:)具体实现:
作为web service服务实现的类必须实现java.rmi.Remote的接口:
package array;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface CountUser extends Remote {
public int countUser(User[] user) throws RemoteException;
}
具体实现远程接口的类:
package array;
public class CountUserImpl implements CountUser {
public int countUser(User[] user){
for(int i=0;i
user[i].getPhone()+ " birthday "+user[i].getBirthDay());
}
return user.length;
}
}
作为数组参数传递的类:
package array;
import java.util.Date;
public class User {
private String name;
private String phone;
private Date birthDay;
public User() {
}
public User(String name,String phone,Date birthDay){
this.name=name;
this.phone=phone;
this.birthDay=birthDay;
}
public void setName(String name) {
this.name = name;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setBirthDay(Date birthDay) {
this.birthDay = birthDay;
}
public String getName() {
return name;
}
public String getPhone() {
return phone;
}
public Date getBirthDay() {
return birthDay;
}
}
使用Jboss_Home/bin 下的wstools工具生成布署j2ee web service 必须的三个文件,jax-rpc映射文件,web服务描述器文件,以及wsdl文档用于wstools工具的配置文件jboss-config.xml类容如下:
xsi:schemaLocation="http://www.jboss.org/jbossws-tools http://www.jboss.org/jbossws-tools/schema/jbossws-tool_1_0.xsd"
使用 wstools -cp array.CountUser -config jboss-config.xml 命令可以生成布署web服务所需的三个文件。另外还得在web.xml文件中把CountUser接口作为servlet发布
仅仅是这样倒也算很容易了,但是wstools工具并不能在映射文件中正确实现User[]的映射。因此还需要手工添加如下代码以实现User[] 到xml之间的映射。
打包成war文件,并且布署。服务端的实现就完成了。打包的war文件下载 使用的Jboss版本4.04
因为篇幅或许还有分类的原因,客户端的实现将记录在下一篇随笔里 如果你想赐教或者讨论,欢迎加入QQ群:30406099
j2ee web service开发(一) 映射数组复杂类型 - 一切从实用出发! - B...
j2ee web service开发(一) 映射数组复杂类型 - 一切从实用出发! - B...
j2ee web service开发(五) 把ejb发布为web服务 - 一切从实用出发!...
j2ee web service开发(五) 把ejb发布为web服务 - 一切从实用出发!...
j2ee web service开发(二) 动态代理与动态调用 - 一切从实用出发! - ...
使用Axis开发Web Service程序
web service开发的完整示例
恶补J2EE Web 开发(讲稿大纲)
一切从实用出发-UC桌面评测 - Windows Mobile手机软件评测 - 91手机平...
在eclipse的环境下使用wtp开发web service
使用Eclipse + MyEclipse开发Web Service的示例!
Windows Mobile中的Web Service应用 - 《msdn开发精选》| W...
在eclipse的环境下使用wtp开发web service
跨越边界: 动态类型语言中的 Web 开发策略
上海华丹信息-快速J2EE开发平台+在线自定义WEB报表引擎(WEB报表 WEB报表打印 ...
Web Service“四长两短”
XML Web Service 基础
什么是Web Service
动态加载Web Service
Web Service入门
XML Web Service
Web Service入门
Web Service Software Factory
XML Web Service 基础