WS问题总结
1、用jax-ws方法生成webservice,如果java类有接口,生成wsdl文件时,会报错,不能有接口。(写上@就行了,如果是复杂的类型,记得放入List<Class>) 这种方法生成服务器端,超简单,比cxf还简单,web.xml都是自动生成的 2、用jax-ws方法生成webservice,不需要再web.xml中写入 <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> 因为jax-ws的这行代码具有加载配置文件的作用(有时不起作用???) <listener> <listener-class> com.sun.xml.ws.transport.http.servlet.WSServletContextListener </listener-class> </listener>
? 4、用cxf写简单的java服务器,以及wsdl2java生成客户端??????????? http://blog.sina.com.cn/s/blog_4979ec3e0101aedx.html ????????????????????????????????????????????????????????????????????????????????????????????????? ???http://www.voidcn.com/article/p-zxgnqrbl-hy.html 5、cxf客户端,方法带参数(只有wsdl的url) /*JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); String wsUrl = "http://127.0.0.1/TSC/TscService.asmx?wsdl"; String method = "SetStage"; Client client = dcf.createClient(wsUrl); Object[] res = null; res = client.invoke(method,(String)obj[1],(String)obj[2],(String)obj[3],(String)obj[4]);*/ cxf客户端(知道接口名和接口路径,知道wsdl的url) JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(IComplexUserService.class); factory.setAddress("http://localhost:8080/CXFWebService/Users"); IComplexUserService service = (IComplexUserService) factory.create(); System.out.println("#############Client getUserByName##############"); User user = service.getUserByName("hoojo"); System.out.println(user); user.setAddress("China-Guangzhou"); service.setUser(user); ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ? 6、Spring+cxf服务器端步骤:a >jar包 ??????????????????????????????????????????????? b >web.xml中servlet配置 ??????????????????????????????????????????????? c >applicationContext.property中导入3个cxf内部的jar包,然后配置jaxws: <jaxws:endpoint id="greenExecution" implementorClass="com.zteits.atms.guard.function.IGreenExecution" implementor="#GreenExecutionImpl" address="/GreenExecution" > </jaxws:endpoint> -----------------------------or-------------------------------------------------------------------------- <bean id="inMessageInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/> <bean?id="outLoggingInterceptor"?class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> <jaxws:server?id="userService"?serviceClass="com.use.test.ws.server.IService"?address="/Users"> <jaxws:serviceBean> <ref bean="userServiceBean"/>?? </jaxws:serviceBean> <jaxws:inInterceptors> <ref bean="inMessageInterceptor"/> </jaxws:inInterceptors> <jaxws:outInterceptors> <ref?bean="outLoggingInterceptor"/>? </jaxws:outInterceptors> </jaxws:server> --------------------------------------------------end----------------------------------------------------------------------------------------------------------------------------------------?????? Spring+cxf客户端步骤:?? a >5个核心jar包 <jaxws:client id="cxfClient" serviceClass="t.ITest" address="http://192.168.1.26:8085/WS_CXF/CxfTest"/> 7、用jax-ws,在myeclipse10中生成ws服务器端,记得写@WebService和@WebMethod,如果不写,会额外产生一个gale..的类(如果没有注入Action,不写@好像也不错) ???? 用cxf,写ws服务器端,也要记得在ITest(接口)写上@WebService和@WebMethod 详见:WS_AXIS练习项目 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |