使用Spring+CXF开发WebService
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 = "http://jdk.study.hermit.org/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;
- 1
- 2
- 3
前往页