ws问题总结(三)
1、WS_AXIS??????????? :只要加上@WebService即可对外暴露多个方法? ???? WS_AXIS_WSS? :只要不加@WebMethod(exclude = true)即可对外暴露多个方法 ???? WS_CXF???????????? :在接口中加上@WebService,不需要加@WebMethod即可对外暴露多个方法 ? 方法参数可以是基本数据类型,或者List<Class>等 package t; import java.util.List; import javax.jws.WebService; @WebService public interface ITests { public String test(String name); public String test2(List<TestPojo> name); }
? 2、ws客户端 WS_CXF_CLIENT???? :b WS_CXF_CLIENT2?? :b WS_CLIENT_JAVA?? :a ? ? a? >? 需要cxf的jar包 package client; import java.util.ArrayList; import java.util.List; import org.apache.cxf.endpoint.Client; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import t.ITests; import t.TestPojo; public class Test { ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); /** * wsdl地址,接口和接口的路径 */ public static void clientToXML(){ JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(ITests.class); factory.setAddress("http://192.168.1.26:8089/WS_CXF/CxfTest"); ITests service = (ITests) factory.create(); TestPojo tp = new TestPojo(); tp.setAge("22岁"); tp.setHigh("185米"); tp.setName("lvxianchao"); List<TestPojo> list = new ArrayList<TestPojo>(); list.add(tp); list.add(tp); list.add(tp); String str = service.test2(list); System.out.println("str: "+str); String str2 = service.test("lvxianchao"); System.out.println("str2: "+str2); } /** * 只有wsdl地址的写法,还有方法名和参数 */ public static void noImplClass(){ JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); String wsUrl = "http://192.168.1.26:8089/WS_CXF/CxfTest?wsdl"; String method = "test"; Client client = dcf.createClient(wsUrl); Object[] res = null; try { res = client.invoke(method,"lvxianchao"); } catch (Exception e) { e.printStackTrace(); } System.out.println("res: "+res.length+"n"+res[0]); } public static void main(String[] args) { // clientToXML(); noImplClass(); } }
b? >? cxf客户端的5个核心jar包,spring+cxf <jaxws:client id="cxfClient" serviceClass="t.ITest" address="http://192.168.1.26:8085/WS_CXF/CxfTest"/>
?-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------分割---------------------------分割---------------------------分割---------------------------分割---------------------------分割---------------------------分割---------------------------分割---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------3、服务器端(4中好用的) WS_AXIS:axis自动化程度比较高 WS_AXIS_WSS:axis手写,比较好用 WS_CXF:总结一中写的,最先接触的spring+cxf的服务器端写法(后来又在这个项目中添加了另一种spring+cxf的服务器端写法,可以配置拦截器,区别于最先接触的那种只有applicationContext中的bean组件的配置有些不同,见下↓) <?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:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.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"/> <!-- 第一种 ==============begin--> <bean id="testImpl" class="t.TestImpl"> </bean> <jaxws:endpoint id="cxftest" implementorClass="t.ITests" implementor="#testImpl" address="/CxfTest" > </jaxws:endpoint> <!-- 第一种 =============end--> <span style="color:#ff0000;"><!-- jaxws-server方式配置cxf服务器端 ===================begin--> <bean id="serviceImpl" class="t2.ServiceImpl"> </bean> <bean id="inMessageInterceptor" class="t2.MessageInterceptor"> <constructor-arg value="receive"></constructor-arg> </bean> <bean id="outLoggingInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> <jaxws:server id="servicer" serviceBean="#serviceImpl" address="/newservice"> <jaxws:inInterceptors> <ref bean="inMessageInterceptor"/> </jaxws:inInterceptors> <jaxws:outInterceptors> <ref bean="outLoggingInterceptor"/> </jaxws:outInterceptors> </jaxws:server> <!-- jaxws-server方式配置cxf服务器端 =====================end--> </span> </beans> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- angularjs – ng-submit和ng-click之间的差异
- bootstrap-为水平排列的表单和内联表单设置可选的图标
- axis客户端访问webservice方法(转)
- 如何使用Angular 2 / Bootstrap 4为ng-bootstrap控件自定义
- 最近用到Bootstrap Multiselect来详细了解一下
- bash – Gradle无法识别我设置的JAVA_HOME
- 灵活定义和处理SOAP头消息
- exchange webservice访问类(日程新增和删除)
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Gly
- docker-compose在docker-compose.yml中看不到卷更改