上篇说了服务端 这下说客户端
userinfo
package com.julongtech.entity;
import java.io.Serializable;
public class UserInfo implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String userId;
private String userName;
private String userPassword;
private String userAge;
private String userSex;
private String userAddress;
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;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public String getUserAge() {
return userAge;
}
public void setUserAge(String userAge) {
this.userAge = userAge;
}
public String getUserSex() {
return userSex;
}
public void setUserSex(String userSex) {
this.userSex = userSex;
}
public String getUserAddress() {
return userAddress;
}
public void setUserAddress(String userAddress) {
this.userAddress = userAddress;
}
public UserInfo() {
super();
}
}
package com.julongtech.service;
public interface UserService {
public String test();
}
package com.julongtech.test;
import java.net.MalformedURLException;
import java.util.List;
import org.codehaus.xfire.XFire;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import com.julongtech.entity.UserInfo;
import com.julongtech.service.CurrentService;
import com.sun.xml.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
public class Test {
/**
* @param args
* @author julong
* @date 2016-6-23 下午11:20:12
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//创建服务接口模板
ObjectServiceFactory objectServiceFactory = new ObjectServiceFactory();
//定义service
Service service = objectServiceFactory.create(CurrentService.class);
//创建xfile对象
XFire xfire = XFireFactory.newInstance().getXFire();
//创建代理工厂
XFireProxyFactory xFireProxyFactory = new XFireProxyFactory(xfire);
String url = "http://localhost:8080/XfireService/services/CurrentService";
try {
CurrentService currentService = (CurrentService) xFireProxyFactory.create(service,url);
String str = currentService.getUser("123");
System.out.println(str);
List<UserInfo> str1 = currentService.sayHello("");
for (UserInfo userInfo : str1) {
System.out.println(userInfo.getUserName());
}
String json = currentService.deleteUser("");
System.out.println("json"+json);
String bytes = currentService.byteTest(null);
System.out.println(bytes);
byte[] b = bytes.getBytes();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.julongtech.service;
import java.util.List;
import com.julongtech.entity.UserInfo;
/**
* webservice的总入口
* @author julong
* @date 2016-6-23 下午10:39:03
*/
public interface CurrentService {
/**
* 获取用户信息
* @param userId
* @return
* @author julong
* @date 2016-6-23 下午10:48:06
*/
public abstract String getUser(String userId);
/**
* 删除用户信息
* @param userId
* @return
* @author julong
* @date 2016-6-23 下午10:48:19
*/
public abstract String deleteUser(String userId);
/**
* 测试程序接口
* @param userName
* @return
* @author julong
* @date 2016-6-23 下午10:49:36
*/
public abstract List<UserInfo> sayHello(String userName);
public abstract String byteTest(String userId);
}
结合上篇 你就能运行出这样的效果
中国人0中国人1中国人2中国人3中国人4json[{"userId":"0","userName":"中国人0","userPassword":"0000000","userAge":"20","userSex":null,"userAddress":"西安0"},{"userId":"1","userName":"中国人1","userAddress":"西安1"},{"userId":"2","userName":"中国人2","userAddress":"西安2"},{"userId":"3","userName":"中国人3","userAddress":"西安3"},{"userId":"4","userName":"中国人4","userAddress":"西安4"}][B@1af678c