微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>



 3、用spring+cxf写客户端,需要有个接口,还需要和服务器端的目录路径一致

 

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);

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
spring整合cxfhttp://www.cnblogs.com/hoojo/archive/2011/03/30/1999563.html

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

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包
                                                b >

			<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练习项目

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐