码迷,mamicode.com
首页 > Web开发 > 详细

用cxf 框架调用webService(第二种,jaxWsServerFactoryBean带接口)

时间:2015-06-09 17:54:19      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

使用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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!