XFire开发Webservice 2:一个简单的Client
?
1:新建普通java工程
2:将Webservice lib下的所有类天加到本工程类路径中
3:将Webservice 的接口(连同包)拷贝到本src中 代用。
4:编写如下测试类并运行看结果:
package client;
import java.net.MalformedURLException;
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.honest.service.UserManagerService;
public class ClientLogin {
?
?public static void main(String[] arg){
???System.out.println(login("honest","huangcheng"));
???System.out.println(login("huangcheng","honest"));
?}
?
?private static boolean login(String name, String password){
??Service userManagerService = new ObjectServiceFactory().create(UserManagerService.class);
??XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());???
??String umsUrl = "http://localhost:8080/ums/services/UserManagerService";
??boolean result = false;
??try {
???UserManagerService service = (UserManagerService) factory.create(userManagerService,umsUrl);
???result = service.login(name, password);???
???
??} catch (MalformedURLException e) {
???
???e.printStackTrace();
??}
??return result;
?}
}