本课题主要解决不同平台和不同应用系统之间的数据转换、数据同步和多个数据源的共享集成问题。为解决该问题,采用基于Web服务的方式来进行数据的交互,主要要考虑如何保持两个系统中的数据能实时同步更新(增加、删除和修改)。
用cxf-2.6.1+spring 3.1.0+ hibernate3.6 版本开发web services
服务端的开发
interface IHelloService
package com.dx.service;
import javax.jws.WebMethod;
import javax.jws.WebService;
import com.dx.model.User;
@WebService
public interface IHelloService {
@WebMethod
public String sayHello(String username);
@WebMethod
public User getUser(int id);
@WebMethod
public void add(User user);
}
IHelloService 的实现 IHelloServiceImpl
package com.dx.service.impl;
import javax.jws.WebMethod;
import javax.jws.WebService;
import com.dx.dao.BaseDao;
import com.dx.model.User;
import com.dx.service.IHelloService;
@WebService
public class IHelloServiceImpl implements IHelloService{
private BaseDao baseDao;
@Override
@WebMethod
public String sayHello(String username) {
return "Hello "+username;
}
@Override
@WebMethod
public User getUser(int id) {
User user = new User();
user.setName("杨钰莹");
user.setId(id);
return user;
}
@Override
@WebMethod
public void add(User user) {
baseDao.save(user);
}
public BaseDao getBaseDao() {
return baseDao;
}
public void setBaseDao(BaseDao baseDao) {
this.baseDao = baseDao;
}
}
spring applicationContext-user.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:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:endpoint id="hellos" address="/Hellows" implementor="#helloService">
</jaxws:endpoint>
<bean id="helloService" class="com.dx.service.impl.IHelloServiceImpl">
<property name="baseDao" ref="baseDao"></property>
</bean>
</beans>
web.xml的配置
<?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.
-->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>cxf</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:context/applicationContext-*.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
好了,接下来部署启动tomcat ,在浏览器输入 http://localhost:8080/cxf_web_010/services
在出现的页面上 点击WSDL : {http://impl.service.dx.com/}IHelloServiceImplService
出现页面
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions name="IHelloServiceImplService" targetNamespace="http://impl.service.dx.com/" xmlns:ns1="http://service.dx.com/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://impl.service.dx.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:import location="http://localhost:8080/cxf_web_010/services/Hellows?wsdl=IHelloService.wsdl" namespace="http://service.dx.com/" />
- <wsdl:binding name="IHelloServiceImplServiceSoapBinding" type="ns1:IHelloService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document" />
- <wsdl:input name="sayHello">
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output name="sayHelloResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="add">
<soap:operation soapAction="" style="document" />
- <wsdl:input name="add">
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output name="addResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="getUser">
<soap:operation soapAction="" style="document" />
- <wsdl:input name="getUser">
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output name="getUserResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="IHelloServiceImplService">
- <wsdl:port binding="tns:IHelloServiceImplServiceSoapBinding" name="IHelloServiceImplPort">
<soap:address location="http://localhost:8080/cxf_web_010/services/Hellows" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
现在web services 已经发布了,下一章编写客户端
分享到:
相关推荐
简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar...
cxf+spring实现webservice
web项目使用spring和cxf的一个开发实例,有简单的代码样例和jar。是一个完整的项目,最终发布完成时访问 http://ip:port/项目名称/webservices/ 就会发现你发布的webservice服务。
CXF+spring+struts实现WebService
cxf+spring+client+springmvc
cxf+spring+tomcat 只是演示,一个helloWorld的例子
使用cxf+spring框架开发webservice的客户端与服务端代码,用于连接两个项目
内容为CXF整合spring的服务端和客户端开发例子,注释不太详尽,网上的教程比较多,但是多跑不起来,特地把整个工程都打包给大家做参考,程序内容均来自网上整理,均可以运行。
基于maven的cxf+spring简单demo,spring版本为4.1.6,cxf版本为3.0.8
cxf+spring+tomat开发webservice所需jar包,该jar包只需解压后导入web工程即可,亲测有用
cxf+spring整合,只要把项目导入到myeclipse中,就可以运行。
cxf+spring开发所必备的jar包压缩包
这是我在使用cxf+spring进行开发中的一点总结,如何搭建开发环境、如何配置dao使用,如何解决乱码问题等的经验分享
CXF+spring+restful创建一个web的接口项目源代码,添加了restful实现的配置及jar包
cxf+spring+jdk1.5开发webService部署weblogic9.2
CXF+Spring+Tomcat发布WebService
代码是我一行行敲的,直接部署就能用,service,client端实现了:(cxf用的是3.0最新的) 1维数组, 2维数组, 3维数组, List, List , Map(adapter方式实现的), 直接返回bean, 返回object[], 做了header的安全认证校验.
基于CXF的WebService服务端和客户端示例,CXF+Spring,希望能为WebService开发者提供帮助。WebService,CXF,Spring.
cxf+spring开发webservice的简单实例,通过查看cfx的doc文档确定wsdl支持所引用的最少jar包
Spring+CXF+tomcat开发webservice,包含服务端和客户端,导入myeclipse就可以用。帮助大家搭建webservice框架,实现webservice功能。