标签:
使用cxf 提供类 JaxWsProxyFactoryBean 来调用 webservice 的服务端.......
JaxWsProxyFactoryBean 是 ClientProxyFactoryBean 的子类...
package cn.itcast.cxf.client; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import cn.itcast.server.JaxInteface.UserService; /** * * 使用JaxWsProxyFactoryBean 调用服务.. * @ 作者 zhuwu@itcast.cn * * 需要依赖一个接口... * */ public class CxfJaxWsInvoke { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //创建调用服务的类... JaxWsProxyFactoryBean bean=new JaxWsProxyFactoryBean(); //设置访问地址 bean.setAddress("http://192.168.9.100:7418/userService"); //设置接口类型... bean.setServiceClass(UserService.class); UserService us=(UserService) bean.create(); String data=us.getUserById(1); System.out.println(data); } }
package cn.itcast.server.JaxInteface; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.ws.RequestWrapper; import javax.xml.ws.ResponseWrapper; /** * This class was generated by the JAX-WS RI. * JAX-WS RI 2.1.1 in JDK 6 * Generated source version: 2.1 * */ @WebService(name = "UserService", targetNamespace = "http://userService.webservice.itcast.cn/") @XmlSeeAlso({ }) public interface UserService { /** * * @param arg0 * @return * returns java.lang.String */ @WebMethod @WebResult(targetNamespace = "") @RequestWrapper(localName = "getUserById", targetNamespace = "http://userService.webservice.itcast.cn/", className = "cn.itcast.server.JaxInteface.GetUserById") @ResponseWrapper(localName = "getUserByIdResponse", targetNamespace = "http://userService.webservice.itcast.cn/", className = "cn.itcast.server.JaxInteface.GetUserByIdResponse") public String getUserById( @WebParam(name = "arg0", targetNamespace = "") int arg0); /** * * @param arg0 */ @WebMethod @RequestWrapper(localName = "addUser", targetNamespace = "http://userService.webservice.itcast.cn/", className = "cn.itcast.server.JaxInteface.AddUser") @ResponseWrapper(localName = "addUserResponse", targetNamespace = "http://userService.webservice.itcast.cn/", className = "cn.itcast.server.JaxInteface.AddUserResponse") public void addUser( @WebParam(name = "arg0", targetNamespace = "") String arg0); }
用cxf 框架调用webService(第二种,jaxWsServerFactoryBean带接口)
标签:
原文地址:http://my.oschina.net/u/2356176/blog/464635