自定义对象类的传递
package webservicedemo;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class CmsBean {
private String name = "";
private int userid=0;
public String getName() {
return name;
}
public void setName(String name){
this.name=name;
}
public int getUserid(){
return userid;
}
public void setUserid(int userid){
this.userid=userid;
}
}
以上是自定义用户类
package webservicedemo.bean;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import webservicedemo.CmsBean;
public class ServerBean {
private int count=0;
public ServerBean() {
}
public static void main(String[] args) {
ServerBean serverBean1 = new ServerBean();
/*CmsBean temp=new CmsBean();
temp.setName("abcd");
temp.setUserid(7);
serverBean1.showCmsBean(temp);*/
CmsBean tmp=serverBean1.getBean();
System.out.println("#########"+(tmp.getUserid()));
System.out.println("#########"+(tmp.getName()));
}
public CmsBean getBean(){
CmsBean temp=new CmsBean();
temp.setName("abcd");
temp.setUserid(8888);
return temp;
}
public int showCmsBean(CmsBean cmsbean){
count++;
System.out.println("#########"+(cmsbean.getUserid()));
System.out.println("#########"+(cmsbean.getName()));
return count;
}
}
以上是服务器端程序代码
package webservicedemo.bean;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.utils.Options;
import org.apache.axis.encoding.XMLType;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import webservicedemo.CmsBean;
public class ClientBean {
public ClientBean() {
}
public static void main(String[] args) {
ClientBean clientBean1 = new ClientBean();
try{
//clientBean1.sendServer();
clientBean1.getServer();
}catch (Exception e){
e.printStackTrace();
}
}
public void getServer() throws Exception{
String endpoint="http://localhost/axis/services/ServerBean";
Service service = new Service();
Call call = (Call) service.createCall();
call.setMaintainSession(true);
QName qn = new QName( "urn:CmsBean", "CmsBean" );
call.registerTypeMapping(CmsBean.class , qn,
new org.apache.axis.encoding.ser.BeanSerializerFactory(CmsBean.class, qn),
new org.apache.axis.encoding.ser.BeanDeserializerFactory(CmsBean.class, qn));
call.setTargetEndpointAddress( new java.net.URL(endpoint));
call.setOperationName( new QName("ServerBean", "getBean") );
call.setReturnType(new QName("ServerBean", "getBean"));
CmsBean result=(CmsBean)call.invoke( new Object[] {});
System.out.println("#########"+(result.getUserid()));
System.out.println("#########"+(result.getName()));
}
public void sendServer() throws Exception{
String endpoint="http://localhost/axis/services/ServerBean";
CmsBean tmp=new CmsBean();
tmp.setName("abcd");
tmp.setUserid(168);
Service service = new Service();
Call call = (Call) service.createCall();
call.setMaintainSession(true);
QName qn = new QName( "urn:CmsBean", "CmsBean" );
call.registerTypeMapping(CmsBean.class , qn,
new org.apache.axis.encoding.ser.BeanSerializerFactory(CmsBean.class, qn),
new org.apache.axis.encoding.ser.BeanDeserializerFactory(CmsBean.class, qn));
call.setTargetEndpointAddress( new java.net.URL(endpoint));
call.setOperationName( new QName("ServerBean", "showCmsBean") );
call.addParameter( "arg1", qn, ParameterMode.IN);
call.setReturnType(XMLType.XSD_INT);
Integer result=(Integer)call.invoke( new Object[] {tmp});
System.out.println(result.intValue());
result=(Integer)call.invoke( new Object[] {tmp});
System.out.println(result.intValue());
}
}
以上为客户端程序代码
<service name="ServerBean" provider="java:RPC">
<!--<requestFlow>
<handler type="authen"/>
</requestFlow>-->
<parameter name="allowedRoles" value="*"/>
<parameter name="className" value="webservicedemo.bean.ServerBean"/>
<parameter name="scope" value="session"/>
<beanMapping qname="ns:CmsBean" xmlns:ns="urn:CmsBean" languageSpecificType="java:webservicedemo.CmsBean"/>
</service>
以上为服务器端配置文件
其中qname="ns:CmsBean" 声明的是
- <wsdl:message name="getBeanResponse">
<wsdl:part name="getBeanReturn" type="tns1:CmsBean" />
</wsdl:message>
WEB服务的自定义数据类型
xmlns:ns="urn:CmsBean"声明的是
- <wsdl:definitions targetNamespace="http://localhost/axis/services/ServerBean" xmlns:impl="http://localhost/axis/services/ServerBean" xmlns:intf="http://localhost/axis/services/ServerBean" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns1="urn:CmsBean" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
名称空间
分享到:
相关推荐
webService—Axis实例webService—Axis实例webService—Axis实例webService—Axis实例webService—Axis实例webService—Axis实例webService—Axis实例
Axis实例Axis入门Axis实例与分析详解
Axis开发Web Service实例Axis开发Web Service实例
AXIS2客户端调用实例 AXIS2客户端调用实例 AXIS2客户端调用实例 AXIS2客户端调用实例
Axis实例与分析详解 实际测试与调试 .doc格式
axis调用实例
《Axis实例与分析详解》.zip
完整的Axis2实例,内含代码demo,编写工具Eclipse,jdk1.7 tomcat7.0
基于seasar2的web services开发实例
NULL 博文链接:https://wfzhanga.iteye.com/blog/1876571
webservice axis 实例
axis2 调用实例axis2 调用实例axis2 调用实例
Tomcat+Axis+WebService 入门实例,讲述如何实现WebService的传递信息,
Java WebService 简单实例 方式二(axis1直接调用方式)
eclipse+axis2学习webservice实例,亲测!
用两个工程模拟实现远程调用对方用webservice提供的接口,并有传送复杂对象数据的例子。
Web Service Axis1.4 完整的实例,WebService Axis1.4 完整的实例。
在开发之前, 先了解一下AXIS,axis目前出现的2版本以其灵活性,快速开发工具的集成高于xfire而使用者居...这是对此版本的基本功能与简单实例的描术) 本人的开发环境eclipse3.2 ,tomcat5.0.28 ,jdk1.4 axis_1.4目前最新版