package org.angus.webservice.object;
import java.io.Serializable;
public class CustomerObj implements Serializable {
private static final long serialVersionUID = -8342351994159763818L;
private String userName;
private String userId;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
web服务:
package org.angus.webservice;
import org.angus.webservice.object.CustomerObj;
public class CustomerObjTest {
public String inCusObj(CustomerObj cusObj)
{
String cusStr = "";
if(cusObj != null)
{
cusStr += "UserId: "+cusObj.getUserId()+
";UserName: "+cusObj.getUserName()+";Age: "+cusObj.getAge();
}
return cusStr;
}
public CustomerObj outCusObj(String userId,String userName,int age)
{
CustomerObj customerObj = new CustomerObj();
customerObj.setUserId(userId);
customerObj.setUserName(userName);
customerObj.setAge(age);
return customerObj;
}
}
将上述java文件编译后的class文件及包文件夹拷贝至axis/WEB-INF/classes目录下<service name="CustomerObjTest" provider="java:RPC">
<parameter name="allowedMethods" value="*" />
<parameter name="className"
value="org.angus.webservice.CustomerObjTest" />
<beanMapping
languageSpecificType="java:org.angus.webservice.object.CustomerObj"
qname="ns1:CustomerObj" xmlns:ns1="urn:BeanService" />
</service>
与之前的部署比较多了languageSpecificType="java:org.angus.webservice.object.CustomerObj"
qname = "ns1:CustomerObj" xmlns:ns1 = "urn:BeanService" />package com.webclient;
import java.net.URL;
import org.angus.webservice.object.CustomerObj;
import org.angus.webservice.object.CustomerObject;
import localhost.axis.services.CustomerObjTest.CustomerObjTest;
import localhost.axis.services.CustomerObjTest.CustomerObjTestService;
import localhost.axis.services.CustomerObjTest.CustomerObjTestServiceLocator;
public class TestClient {
/**
* @param args
*/
public static void main(String[] args)throws Exception {
try
{
//自定义对象(简单类型)测试
CustomerObjTestService CustomerObjService = new CustomerObjTestServiceLocator();
//CustomerObjTest customerObjTest = CustomerObjService.getCustomerObjTest();
CustomerObjTest customerObjTest = CustomerObjService.getCustomerObjTest(new URL("http://localhost:8080/axis/services/CustomerObjTest"));
CustomerObj customerObj = new CustomerObj();
customerObj.setUserId("25");
customerObj.setUserName("钰莹");
customerObj.setAge(20);
String customerStr = customerObjTest.inCusObj(customerObj);
System.out.println(customerStr);
CustomerObj outCustomerObj = customerObjTest.outCusObj("99", "晓明", 25);
System.out.println("ID: "+outCustomerObj.getUserId()+
"Name: "+outCustomerObj.getUserName()+
"Age: "+outCustomerObj.getAge());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}