文档详情

CXF+SPRING.doc

发布:2017-04-04约6.95千字共6页下载文档
文本预览下载声明
Apache CXF 提供方便的Spring整合方法,可以通过注解、Spring标签式配置来暴露Web Services和消费Web Services 各种类型的Annotation。@WebService和@WebMethod是WSDL映射Annatotion。这些Annotation将描述Web Service的WSDL文档元素和Java源代码联系在一起。@SOAPBinding是一个绑定的annotation用来说明网络协议和格式。 1、@WebService annotation的元素name,serviceName和targetNamespace成员用来描述 wsdl:portType,wsdl:service,和targetNameSpace生成WebService中的WSDL文件。 2、@SOAPBinding是一个用来描述SOAP格式和RPC的协议的绑定Annotation。 3、@WebMethod Annotation的operationName成员描述了wsdl:operation,而且它的操作描 述了WSDL文档中的SOAPAction头部。这是客户端必须要放入到SQAPHeader中的数 值,SOAP 1.1中的一种约束。 4、@WebParam Annotation的partName成员描述了WSDL文档中的wsdl:part。 5、@WebResult Annotation的partName成员描述了wsdl:part用来返回WSDL文档的值。 例如下面使用annotation定义了一个webservice: import java.util.List; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; import com.cxf.pojo.User; @WebService(targetNamespace = /client) public interface UserService { @WebMethod(operationName=Insert) public void insert( @WebParam(name = userId) String userid, @WebParam(name = userName) String username, @WebParam(name = userEmail) String useremail, @WebParam(name = userAge) int userage); @WebMethod(operationName=GetUserById) @WebResult(name = result) public User getUserById(@WebParam(name=userid) String userid); @WebMethod(operationName=GetAllUsers) @WebResult(name = result) public List getAllUsers(); } 其实现类如下所示: import java.util.List; import javax.jws.WebService; import com.cxf.dao.UserDao; import com.cxf.pojo.User; import com.cxf.service.UserService; @WebService(endpointInterface=com.cxf.service.UserService) public class UserServiceImpl implements UserService { private UserDao userDao; public List getAllUsers() { return userDao.findAllUser(); } public User getUserById(String userid) { return userDao.findUserById(userid); } public void insert(String userid, String username, String useremail, int userage) { User user=new User(); user.setUserage(userage)
显示全部
相似文档