服务端
1.必须jar包:cxf-2.6.1.jar
2.spring-cxf.xml配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:meta-inf/cxf/cxf.xml" /> <import resource="classpath:meta-inf/cxf/cxf-extension-soap.xml" /> <import resource="classpath:meta-inf/cxf/cxf-servlet.xml" /> <bean id="checksystemserviceimp" class="a.rst.checksystem.server.CheckSystemServiceImp"> </bean> <jaxws:endpoint id="webservice" implementor="#checksystemserviceimp" address="/webservice"> </jaxws:endpoint> </beans>
3. web.xml配置spring-cxf.xml
<listener> <listener-class>com.chinavvv.util.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-cxf.xml </param-value> </context-param>
<!--还需要配置以下servlet-->
<servlet> <servlet-name>CXFService</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFService</servlet-name> <url-pattern>/service/*</url-pattern> </servlet-mapping>
4. java类、接口如下,包含接口CheckSystemService、接口实现类CheckSystemServiceImp
package a.rst.checksystem.server; import javax.jws.WebParam; import javax.jws.WebService; @WebService public interface CheckSystemService { public void test(@WebParam(name="param") String param); public String checkWebSer(String aac002,String aac003,String aab301) throws Exception; }
@WebService(endpointInterface = "a.rst.checksystem.server.CheckSystemService") public class CheckSystemServiceImp implements CheckSystemService { public void test(String param) { System.out.println("001webservice is success "); System.out.println("002dao is annotationed? "+relectdao); System.out.println("003url param:"+param); } public String checkWebSer(String aac002,String aab301) throws Exception { Ceshibean bean=new CeshiBean();//这里是自定义的Javabean return jsontToString(PersonalInfo);// 返回类型设置为json格式的字符串,没有使用Bean } private String jsontToString(Object o){ JsonConfig jsonConfig = new JsonConfig(); //建立配置文件 jsonConfig.setIgnoreDefaultExcludes(false); //设置默认忽略 jsonConfig.setExcludes(new String[]{"child","multipartRequestHandler","resultValueMap","servletWrapper","validatorResults"}); //net.sf.json.JSONObject jsonbean = net.sf.json.JSONObject.fromObject(bean,jsonConfig); JSONObject json = JSONObject.fromObject(o,jsonConfig); return json.toString(); } }
测试是否发布成功地址:http://127.0.0.1:8080/service/webservice?wsdl
客户端:
cd d:/java/bin
wsimport - keep -p com.webservice.client http://127.0.0.1:8080/service/webservice?wsdl
用Java api生成客户端包,以上命令将在d:/java/bin目录下生成com.webservice.client包。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。