深入研究AXIS实例 ApacheSOAPBeanXMLC
程序员文章站
2022-05-29 12:32:57
...
自定义对象类的传递
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/">
名称空间
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/">
名称空间
上一篇: Java基础系列--08_集合1
下一篇: 赤壁之战第一功臣黄盖最后是怎么死的
推荐阅读
-
axis2通过城市名称调用.net写的asmx WebService查询天气实例
-
(1)使用Axis2方式发布webService实例说明
-
axis2客户端调用免费的webservice服务的实例之三axis2使用RPC方
-
axis2客户端调用免费的webservice服务的实例之二纯手动调用免费
-
超简单AXIS实例 ApacheCC++C#Web
-
深入研究AXIS实例 ApacheSOAPBeanXMLC
-
Axis2 创建webService实例
-
axis2通过城市名称调用.net写的asmx WebService查询天气实例
-
axis2发布webservice各种方式实例
-
Axis2 创建webService实例