在上一篇文章Java WebServices教程(1)-使用XFire当中我们介绍了xfire建立服务器端。
接下来我们在客户端调用这个web服务。
首先我们也应该有一个和服务端完全一致的接口,包名也应该一致!
public interface IHelloService {
public List<User> getAllUser();
public String sayHi(String uname);
}
package com.pengzj.service.invoke;
import java.util.List;
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.pengzj.service.IHelloService;
import com.pengzj.service.User;
public class ClientTest {
/**
* @param args
* @author pengzj
*@date Jun 17,2010
*/
public static void main(String[] args) {
Service servicemodel =new ObjectServiceFactory().create(IHelloService.class);
XFireProxyFactory factory =new XFireProxyFactory(XFireFactory.newInstance().getXFire());
String serviceUrl="http://localhost:8080/cxfService_0617/services/Hellows";
try{
IHelloService hellows =(IHelloService)factory.create(servicemodel,serviceUrl);
System.out.println(hellows.sayHi("jack"));
}catch (Exception e) {
e.printstacktrace();
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。