一、服务端实现。
1.CXF必须包;
2.applicationcontext.xml里面加入
(1)头文件:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
(2)暴露接口
/* http://ip:端口/项目名/web.xml配置cxf路径/applicationcontext.xml配置路径*/
/* http://localhost:7001/doubleRecord/recordServices/obtainPolicyInfo?wsdl 查看文档*/
/* http://localhost:7001/doubleRecord/recordServices/列出此路径下所有方法*/
//spring中配置class路径
3.web.xml程序加载引入CXF
Apache-Axis Servlet
AxisServlet
org.apache.axis.transport.http.AxisServlet
AxisServlet
/servlet/AxisServlet
AxisServlet
*.jws
AxisServlet
/recordServices/*
CXFServlet
org.apache.cxf.transport.servlet.CXFServlet
1
CXFServlet
/recordServices/*//CXF路径
4.需要暴露的接口类用@webservice注解,方法用@webMethod。
service接口:
@WebService(name = "obtainPolicyInfoService", targetNamespace = "http://facade.service.survey.com")
public interface ObtainPolicyInfoService {
@WebMethod(operationName = "getPolicyInfo", action = "")
@WebResult(name = "return", targetNamespace = "")
public String obtainPolicyInfo(@WebParam(name="arg0",targetNamespace = "")ObtainPolicyInfoDomain policyInfo);
}
Service实现类:
@WebService(endpointInterface = "com.sinosoft.survey.service.facade.ObtainPolicyInfoService")
public class ObtainPolicyInfoServiceSpringImpl implements ObtainPolicyInfoService {
/* http://localhost:7001/doubleRecord/recordServices/obtainPolicyInfo/getPolicyInfo */
private static final Log logger = LogFactory.getLog(ObtainPolicyInfoServiceSpringImpl.class);
private PolicyMainInfoService policyMainInfoService;
@WebMethod(operationName = "getPolicyInfo")
@WebResult(name = "result")
public String obtainPolicyInfo(ObtainPolicyInfoDomain policyInfo){
//业务
return "你好!"
}
}
传输对象:全是String类型
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "arg0", propOrder = { "PolicyNo", "certiType","certiNo" })
public class ObtainPolicyInfoDomain implements Serializable {
private String PolicyNo;
private String certiType;
private String certiNo;
public ObtainPolicyInfoDomain(){}
public ObtainPolicyInfoDomain(String policyNo, String certiType, String certiNo) {
PolicyNo = policyNo;
this.certiType = certiType;
this.certiNo = certiNo;
}
//get\set方法
}
5.测试:使用soapUI测试 不能使用postman.soap=http+xml,postman只是http
二、客户端实现。
1.启动服务端程序,浏览器输入地址http://localhost:8080/YYY/ewebservice。选择需要调用的接口方法。点击得到wsdl地址
http://localhost:8080/YYY/ewebservice/s2?wsdl。
2.新建工程使用Myeclipse自动生成客户端代码,右键工程选择other,新建webservice client,将wsdl地址输入,finish即可,客户端代码产生好了。写测试类调用方法
public class tttt {
public static void main(String[] args) throws RemoteException,
ServiceException {
StorageHServiceProxy sp=new StorageHServiceProxy();
System.out.println(sp.getT("4"));
}
}