SSM之Web Services

2024-05-09 23:08
文章标签 ssm web services

本文主要是介绍SSM之Web Services,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

    • 1.介绍
      • 1.1 wsdl介绍
      • 1.2 项目结构
    • 2.axis2集成
      • 2.1 添加依赖
      • 2.2 创建相关类
      • 2.3 applicationContext.xml
      • 2.4 web.xml
      • 2.5 添加services.xml
      • 2.5 运行
    • 参考

1.介绍

WebService基本介绍
WebService中的WSDL详细解析

1.1 wsdl介绍

在这里插入图片描述

    <wsdl:service name="HelloServiceDemo"><wsdl:port name="HelloServiceDemoHttpSoap11Endpoint" binding="ns:HelloServiceDemoSoap11Binding"><soap:address location="http://localhost:8080/ssm_crud/services/HelloServiceDemo.HelloServiceDemoHttpSoap11Endpoint/"/></wsdl:port></wsdl:service>

从下面可以看到soap:operation soapAction=“urn:sayHello”,urn:sayHello就是我们要访问的方法名

    <wsdl:binding name="HelloServiceDemoSoap11Binding" type="ns:HelloServiceDemoPortType"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><wsdl:operation name="sayHello"><soap:operation soapAction="urn:sayHello" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding>
    <wsdl:portType name="HelloServiceDemoPortType"><wsdl:operation name="sayHello"><wsdl:input message="ns:sayHelloRequest" wsaw:Action="urn:sayHello"/><wsdl:output message="ns:sayHelloResponse" wsaw:Action="urn:sayHelloResponse"/></wsdl:operation></wsdl:portType>
    <wsdl:message name="sayHelloRequest"><wsdl:part name="parameters" element="ns:sayHello"/></wsdl:message><wsdl:message name="sayHelloResponse"><wsdl:part name="parameters" element="ns:sayHelloResponse"/></wsdl:message>
    <wsdl:types><xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://serviceimpl.webservice.zy.com"><xs:element name="sayHello"><xs:complexType><xs:sequence><xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/></xs:sequence></xs:complexType></xs:element><xs:element name="sayHelloResponse"><xs:complexType><xs:sequence><xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/></xs:sequence></xs:complexType></xs:element></xs:schema></wsdl:types>

1.2 项目结构

在这里插入图片描述

2.axis2集成

2.1 添加依赖

	<axis2.version>1.7.8</axis2.version><!--axis2 begin--><dependency><groupId>org.apache.axis2</groupId><artifactId>axis2-spring</artifactId><version>${axis2.version}</version></dependency><dependency><groupId>org.apache.axis2</groupId><artifactId>axis2-transport-http</artifactId><version>${axis2.version}</version></dependency><dependency><groupId>org.apache.axis2</groupId><artifactId>axis2-transport-local</artifactId><version>${axis2.version}</version></dependency><dependency><groupId>org.apache.axis2</groupId><artifactId>axis2-xmlbeans</artifactId><version>${axis2.version}</version></dependency><!--axis2 end-->

2.2 创建相关类

public interface IHelloService {public String sayHello(String name);
}
@Service("helloService")
public class HelloServiceImpl implements IHelloService{@Overridepublic String sayHello(String name) {return "你好,"+name+" 欢迎来到websercie!!!";}
}

2.3 applicationContext.xml

    <!--axi2交给spring管理--><bean id="applicationContext"class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />

2.4 web.xml

  <!-- 开启webservice:Axis2 --><servlet><display-name>Apache-Axis Servlet</display-name><servlet-name>AxisServlet</servlet-name><servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class><load-on-startup>2</load-on-startup></servlet><servlet-mapping><servlet-name>AxisServlet</servlet-name><url-pattern>*.jws</url-pattern></servlet-mapping><servlet-mapping><servlet-name>AxisServlet</servlet-name><url-pattern>/services/*</url-pattern></servlet-mapping><!-- Axis2 -->

2.5 添加services.xml

注意:services.xml的目录结构必须按照这下面路径设置,不然会读取不到这个配置文件的
/webapp/WEB-INF/services/webservices/META-INF/services.xml ,其中,只有webservices可以任意命名,其他的文件夹名称不能改变

<?xml version="1.0" encoding="UTF-8"?>
<serviceGroup><!--接口名称--><service name="HelloServiceDemo" scope="application"><!--接口描述--><description>axis2 实现的webservice样例</description><!--这个是比较老的接口,若spring版本较高,用第二个,不然启动不能实例化--><!--<parameter name="ServiceObjectSupplier">--><!--org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier--><!--</parameter>--><parameter name="ServiceObjectSupplier" locked="false">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter><!--接口实现类--><parameter name="SpringBeanName">helloService</parameter><messageReceivers><messageReceiver mep="http://www.w3.org/ns/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/><messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/></messageReceivers></service>
</serviceGroup>

2.5 运行

输入:IP+端口+项目名+services+接口名?wsdl
http://localhost:8080/ssm_crud/services/HelloServiceDemo?wsdl
在这里插入图片描述
用soapui访问,如图:
在这里插入图片描述

参考

官网
官网
springMVC以maven方式集成axis2-1.7.8
spring整合axis2(最小配置化)的示例
maven下axis2与spring的整合开发流程

这篇关于SSM之Web Services的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/974768

相关文章

Web服务器-Nginx-高并发问题

《Web服务器-Nginx-高并发问题》Nginx通过事件驱动、I/O多路复用和异步非阻塞技术高效处理高并发,结合动静分离和限流策略,提升性能与稳定性... 目录前言一、架构1. 原生多进程架构2. 事件驱动模型3. IO多路复用4. 异步非阻塞 I/O5. Nginx高并发配置实战二、动静分离1. 职责2

SpringBoot通过main方法启动web项目实践

《SpringBoot通过main方法启动web项目实践》SpringBoot通过SpringApplication.run()启动Web项目,自动推断应用类型,加载初始化器与监听器,配置Spring... 目录1. 启动入口:SpringApplication.run()2. SpringApplicat

Python Web框架Flask、Streamlit、FastAPI示例详解

《PythonWeb框架Flask、Streamlit、FastAPI示例详解》本文对比分析了Flask、Streamlit和FastAPI三大PythonWeb框架:Flask轻量灵活适合传统应用... 目录概述Flask详解Flask简介安装和基础配置核心概念路由和视图模板系统数据库集成实际示例Stre

如何使用Maven创建web目录结构

《如何使用Maven创建web目录结构》:本文主要介绍如何使用Maven创建web目录结构的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录创建web工程第一步第二步第三步第四步第五步第六步第七步总结创建web工程第一步js通过Maven骨架创pytho

Java Web实现类似Excel表格锁定功能实战教程

《JavaWeb实现类似Excel表格锁定功能实战教程》本文将详细介绍通过创建特定div元素并利用CSS布局和JavaScript事件监听来实现类似Excel的锁定行和列效果的方法,感兴趣的朋友跟随... 目录1. 模拟Excel表格锁定功能2. 创建3个div元素实现表格锁定2.1 div元素布局设计2.

如何使用Haporxy搭建Web群集

《如何使用Haporxy搭建Web群集》Haproxy是目前比较流行的一种群集调度工具,同类群集调度工具有很多如LVS和Nginx,本案例介绍使用Haproxy及Nginx搭建一套Web群集,感兴趣的... 目录一、案例分析1.案例概述2.案例前置知识点2.1 HTTP请求2.2 负载均衡常用调度算法 2.

python web 开发之Flask中间件与请求处理钩子的最佳实践

《pythonweb开发之Flask中间件与请求处理钩子的最佳实践》Flask作为轻量级Web框架,提供了灵活的请求处理机制,中间件和请求钩子允许开发者在请求处理的不同阶段插入自定义逻辑,实现诸如... 目录Flask中间件与请求处理钩子完全指南1. 引言2. 请求处理生命周期概述3. 请求钩子详解3.1

SpringBoot项目Web拦截器使用的多种方式

《SpringBoot项目Web拦截器使用的多种方式》在SpringBoot应用中,Web拦截器(Interceptor)是一种用于在请求处理的不同阶段执行自定义逻辑的机制,下面给大家介绍Sprin... 目录一、实现 HandlerInterceptor 接口1、创建HandlerInterceptor实

Web技术与Nginx网站环境部署教程

《Web技术与Nginx网站环境部署教程》:本文主要介绍Web技术与Nginx网站环境部署教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Web基础1.域名系统DNS2.Hosts文件3.DNS4.域名注册二.网页与html1.网页概述2.HTML概述3.

Python使用Reflex构建现代Web应用的完全指南

《Python使用Reflex构建现代Web应用的完全指南》这篇文章为大家深入介绍了Reflex框架的设计理念,技术特性,项目结构,核心API,实际开发流程以及与其他框架的对比和部署建议,感兴趣的小伙... 目录什么是 ReFlex?为什么选择 Reflex?安装与环境配置构建你的第一个应用核心概念解析组件