- 浏览: 112176 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
ron.luo:
干货,必须得顶。
JAXB使用经验总结 -
csdn_zuoqiang:
能否看下DWR的配置情况?谢谢
结合webservice实现dwr推送 -
友友水:
。。。。不好意思,无心之失,删不掉前一条评论
JAXB使用经验总结 -
友友水:
[/flash][/flash][/flash][/flash ...
JAXB使用经验总结 -
lihong11:
大哥,加加注释好不?看不懂唉
小玩dwr实现服务器推送
webService使用总结
- 博客分类:
- web
webService 是什么就不解释了,webservice有很多种开发方式,也有很多种调用方式,自己实际中用到的一种现在描述如下:
服务端的开发使用到apache CXF的开发方式,比较效率。
1.新建一个web项目,把apache-cxf-x.x.x\lib下的jar包添加到项目中,(加哪些看具体需要)
2.写好你的接口与实现类。(这里数据绑定方式使用cxf默认的jaxb,你也可以用其它的比如 aegis)
3.写好了之后就是发布服务了,发布方式也有好几种,这里采用的是cxf+spring整合在tomcat下发布的方式.具体的配置如下: applicationContext.xml
配置文件中只列出了跟cxf发布服务有关的,涉及到的接口名虽然原名复制了过来,但看看也没什么关系
当然,你还需要在你的web.xml文件中配置cxf的servlet,具体如下:
这样,发布服务就成了启动tomcat了,查看发布是否成功,看以访问这个链接:http://localhost:8080/xx/xx
客户端的调用
客户端调用有很多种形式,比如常见的可能是要用到AXIS来生成一堆客户端代码放进客户端程序,然后在客户端程序的配置文件中如下配置:xxxx.xml
然后呢,在你的程序里就可以调用webservice的接口了,我写了一个调用接口的工具类:
这样,在你的代码中就可以如下实现调用接口方法了:
发布与调用的方式有很多种,看你的需要了。。。
服务端的开发使用到apache CXF的开发方式,比较效率。
1.新建一个web项目,把apache-cxf-x.x.x\lib下的jar包添加到项目中,(加哪些看具体需要)
2.写好你的接口与实现类。(这里数据绑定方式使用cxf默认的jaxb,你也可以用其它的比如 aegis)
3.写好了之后就是发布服务了,发布方式也有好几种,这里采用的是cxf+spring整合在tomcat下发布的方式.具体的配置如下: applicationContext.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-lazy-init="true"> <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" /> <jaxws:endpoint id="importDataEndPoint" implementor="#importDataService" address="/ImportDataService" /> <jaxws:endpoint id="dashboardDataEndPoint" implementor="#dashboardDataService" address="/DashboardDataService" /> <jaxws:endpoint id="inventoryEndPoint" implementor="#inventoryService" address="/InventoryService" /> <jaxws:endpoint id="emailEndPoint" implementor="#emailService" address="/EmailService" /> <jaxws:endpoint id="importDataDBPointLoadingEndPoint" implementor="#importDataDBPointLoadingService" address="/ImportDataDBPointLoadingService" /> <jaxws:endpoint id="dashboardDataCalculationEndPoint" implementor="#dashboardDataCalculationService" address="/DashboardDataCalculationService" /> <jaxws:endpoint id="upsModulesEndPoint" implementor="#upsModulesService" address="/UpsModulesService" /> <bean id="SpringContextHolder" lazy-init="false" class="com.accentrix.nttca.dcms.dashboard.util.SpringContextHolder" /> </beans> <!-- END SNIPPET: beans -->
配置文件中只列出了跟cxf发布服务有关的,涉及到的接口名虽然原名复制了过来,但看看也没什么关系
当然,你还需要在你的web.xml文件中配置cxf的servlet,具体如下:
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>CXFServlet</servlet-name> <display-name>CXF Servlet</display-name> <servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
这样,发布服务就成了启动tomcat了,查看发布是否成功,看以访问这个链接:http://localhost:8080/xx/xx
客户端的调用
客户端调用有很多种形式,比如常见的可能是要用到AXIS来生成一堆客户端代码放进客户端程序,然后在客户端程序的配置文件中如下配置:xxxx.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> <jaxws:client id="importDataService" serviceClass="xxxx.dashboard.service.ImportDataService" address="http://xxxx:8080/xxxxx/ImportDataService" /> ....
然后呢,在你的程序里就可以调用webservice的接口了,我写了一个调用接口的工具类:
import org.springframework.context.support.ClassPathXmlApplicationContext; public class CxfUtil { public static <T> T getService(String name, Class<T> requiredType) { return ApplicationContextHolder.context.getBean(name, requiredType); } public static <T> T getService(Class<T> requiredType) { return ApplicationContextHolder.context.getBean(requiredType); } private static class ApplicationContextHolder { private static ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "META-INF/xxxx.xml" }); } }
这样,在你的代码中就可以如下实现调用接口方法了:
ImportDataService ds = CxfUtil .getService(ImportDataService.class); ds.doxxx(); ....
发布与调用的方式有很多种,看你的需要了。。。
发表评论
-
http简易工具类
2018-09-21 09:20 412http简易工具类, 方便http调用 -
微信JSSDK之添加微信卡券
2016-05-31 09:37 719微信卡券的使用,是在之前的微信jsapi基础上,再加上一次卡券 ... -
hibernate延迟加载 与 web应用 独立缓存架构的冲突
2013-04-26 11:03 1091延迟加载(Lazy Loading)是 ... -
jquery验证框架使用
2013-03-27 16:57 12831.使用jquery的表单验证框架,需要导入jquery的库文 ... -
结合webservice实现dwr推送
2012-08-22 13:26 5274情景: 客户端需要实时提醒服务,比如某个日程已过期的提醒, ... -
copy到粘贴板
2012-05-22 11:39 1146直接上代码,实现了IE和火狐下的copy content ... -
小玩dwr实现服务器推送
2012-01-19 17:01 5556最近项目有需要用到‘推’,就是服务器端自动把消息推给客户端,就 ... -
jquery之事件error小提醒
2011-12-13 15:27 1372今天用到jquery的事件中的error方法,发现当标签img ... -
小想法
2011-10-17 16:48 0刚才有个想法,不知道是由什么联想而来,最近淘宝大战,看了些文章 ... -
原来这个如此容易 ---- 点击弹出确认框
2011-10-12 15:51 1273今天无意识的看到了点击按钮弹出确认框的 javascri ... -
groovy 小应用
2011-09-30 10:25 1138昨天使用groovy脚本生成大量的sql,实在是爽! 现 ... -
JAXB使用经验总结
2011-09-27 11:13 9182使用JAXB首先要知道它是干什么的 当然,切入正题 ... -
Jquery资料链接(供学习)
2011-08-08 17:16 662提供些资料链接,以备查找 http://jquery.com ... -
dwr使用小结
2011-08-05 15:32 1066很久没上来冒泡了 ,把dwr的使用经验搁上来,以后备用。 ... -
实践中filter的配置
2011-04-26 09:23 862配置一个权限filter,拦截一切没有登录却想访问只有登录后才 ... -
JSTL问题解决之-->报找不到C标签
2011-03-30 13:51 3037当jsp页面显示报找不到C:标签时的解决办法 在li ... -
jsp之自定义标签
2011-03-29 11:09 847http://javakeith.iteye.com/blog ... -
jsp之session对象
2011-03-29 11:06 839http://javakeith.iteye.com/blo ... -
jsp内置对象
2011-03-29 11:04 966感谢兄弟的总结 http://javakeith.iteye. ... -
JSTL自定义标签过程
2011-03-29 10:39 7274要定义自己的标签,首先写个java类,extends TagS ...
相关推荐
webservice使用总结
JavaScript调用WebService实例总结
用delphi调用dotnet开发的webservice经验总结,包含汉字乱码,soapheader安全验证的问题。
delphi开发webservice经验总结
使用gsoap进行webservice开发总结.pdf
WebService学习过程中,知识点的总结,和例子。
nodejs和Java调用webservice接口总结 做了一天终于调通了 Java和node工程都是可以使用,随便总结一下,下次忘记咯
java调用webservice的各种方法总结java调用webservice的各种方法总结
利用gsoap进行webservice开发总结.docx利用gsoap进行webservice开发总结.docx
WebService\Ajax的总结,全方面介绍了.net下的webservice和ajax原理以及扩展空间。
jquery调用webservice总结.重点是从实践中学习到如何用jquery调用webservice。
WebService接口开发实战总结以及调试。
eclipse创建Webservice以及调用Webservice总结
个人的使用axis2开发webservice项目的总结文档
cxf实现webservice全面总结,包括实现例子,cxf进阶篇、cxf高级篇,谢谢大家参考
Axis2开发webservice总结,资源一般,希望对大家有用
Eclipse 开发 Axis_WebService 实例总结
java_调用webservice的各种方法总结
Axis2开发webservice总结
webservice开发总结,全是本人自己的总结