深入研究AXIS实例

自定义对象类的传递

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/">

名称空间
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值