Spring+CXF开发基于SOAP协议的WebService
来源:互联网 发布:淘宝专业版免费模板 编辑:程序博客网 时间:2024/06/05 00:57
spring+CXF开发SOAP协议的WebService
使用apache-cxf-2.7.18版本的cxf相关jar包
一、项目结构图——服务端:
服务接口:IWeatherInterface.java
package com.zxj.weather.ws;import javax.jws.WebService;import javax.xml.ws.BindingType;import javax.xml.ws.soap.SOAPBinding;@WebService@BindingType(SOAPBinding.SOAP12HTTP_BINDING)public interface IWeatherInterface { public String getWeather(String cityName);}
服务接口实现类:WeatherInterfaceImpl.java
package com.zxj.weather.ws.impl;import javax.jws.WebService;import org.springframework.stereotype.Component;import com.zxj.weather.ws.IWeatherInterface;@Component("weatherInterfaceImpl")@WebServicepublic class WeatherInterfaceImpl implements IWeatherInterface { @Override public String getWeather(String cityName) { System.out.println("来自于客户端:"+cityName); return "晴"; }}
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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> <!-- 自动扫描 --> <context:component-scan base-package="com.zxj.weather.ws" /> <!-- 定义服务提供者 --> <jaxws:endpoint address="/weather" implementor="#weatherInterfaceImpl"> <!-- 添加in拦截器 --> <jaxws:inInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" /> </jaxws:inInterceptors> <!-- 添加out拦截器 --> <jaxws:outInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" /> </jaxws:outInterceptors> </jaxws:endpoint></beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>ws_cxf_spring_server</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <!-- Spring配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- Spring监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/webservice/*</url-pattern> </servlet-mapping></web-app>
二、项目结构图——客户端:
1、在dos窗口中,通过wsdl2java生成客户端代码
wsdl2java -d . -p com.zxj.weather.ws.impl http://127.0.0.1:8080/ws_cxf_spring_server/webservice/weather?wsdl
备注:
-d . 代表在当前文件夹中生成代码
-p com.zxj.weather.ws.impl 代表生成代码的包名
2、生成的客户端代码列表如下:
3、调用web服务的类:WeatherClient.java
package com.zxj.weather.ws.client;import com.zxj.weather.ws.impl.IWeatherInterface;import com.zxj.weather.ws.impl.WeatherInterfaceImplService;public class WeatherClient { public static void main(String[] args) { WeatherInterfaceImplService weatherInterfaceImplService = new WeatherInterfaceImplService(); IWeatherInterface weatherInterface = weatherInterfaceImplService.getWeatherInterfaceImplPort(); String weather = weatherInterface.getWeather("成都"); System.out.println("成都:"+weather); }}
0 0
- Spring+CXF开发基于SOAP协议的WebService
- CXF Spring开发WebService,基于SOAP和REST方式
- CXF Spring开发WebService,基于SOAP和REST方式
- CXF Spring开发WebService,基于SOAP和REST方式
- cxf基于soap的webservice
- webservice--CXF+Spring整合发布SOAP协议的服务
- 基于CXF框架下的SOAP Webservice服务端接口开发
- Spring整合CXF发布基于SOAP协议的服务
- CXF结合Spring 开发SOAP WebService服务
- SpringBoot整合CXF开发基于soap协议的服务
- webservice--CXF发布SOAP协议的服务
- WebService(4):CXF Spring开发WebService,基于SOAP和REST方式
- 基于CXF的webservice开发
- 基于Spring和CXF的webservice开发环境搭建
- 基于Spring和CXF的webservice开发环境搭建
- webservice cxf -- 基于soap方式开发(一)
- JAVA采用CXF框架开发基于JAX-WS(SOAP)规范的WebService服务器端
- Java WebService-CXF-基于SOAP的Web服务
- 十步学习法
- 如何提高工作效率
- 开发Java准备
- 关于silly
- 集成开发环境MyEclipse介绍
- Spring+CXF开发基于SOAP协议的WebService
- Runtime类的用法
- Java程序的参数
- Scanner类的使用
- java十进制数字转十六进制(int类型太大无法转换,把int类型转为Long类型计算)
- HTTP中application/x-www-form-urlencoded字符说明
- System类典型用法
- Linux 下ssh创建ip加密码隧道
- Object类的典型应用