webservice有两大类:RPC和Document。
共有五种风格:RPC/encoded 、RPC/literal、Document/literal、Document/literal wrapped、Document/literal non-wrapped
RPC/encoded :可读性高。格式验证困难,且性能受限于其格式的解析,不被ws-i接受。
RPC/literal :可读性高。格式验证困难,被ws-i接受。
Document/literal:格式验证简单,被ws-i有条件接受。无方法名,可读性差。
Document/literal wrapped:格式验证简单,被ws-i接受。有方法名,可读性非常差。不支持方法重载。
Document/literal non-wrapped:格式验证简单,被ws-i接受。无方法名,可读性非常差。支持方法重载。
其中Document格式被任务是趋势,RPC是较为陈旧的方式,但为什么要用RPC/encoded?
很简单已经存在的项目正在使用,而改造费用太大。
所以要用十年前的axis1(2006年的1.4版,相比其他webservice实现,其性能是最差的) !
方法: 建立一个maven webapp项目,加入相关依赖。添加springmvc的servlet和axis的servlet。添加类和wsdd文件。关键代码如下。
除了spring自己的包,还需要依赖:
<dependency> <groupId>org.apache.axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>commons-discovery</groupId> <artifactId>commons-discovery</artifactId> <version>0.5</version> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0.2</version> </dependency> <dependency> <groupId>javax.xml.rpc</groupId> <artifactId>javax.xml.rpc-api</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> <version>1.6.3</version> </dependency>
web.xml同级增加文件:server-config.wsdd
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" /> <!-- 系统服务 --> <service name="AdminService" provider="java:MSG"> <parameter name="allowedMethods" value="AdminService" /> <parameter name="enableRemoteAdmin" value="false" /> <parameter name="className" value="org.apache.axis.utils.Admin" /> <namespace>http://xml.apache.org/axis/wsdd/</namespace> </service> <service name="Version" provider="java:RPC"> <parameter name="allowedMethods" value="getVersion" /> <parameter name="className" value="org.apache.axis.Version" /> </service> <!-- 自定义服务 --> <service name="myWebService" provider="java:RPC"> <parameter name="className" value="test.HelloWorldWebService" /> <parameter name="allowedMethods" value="*" /> </service> <transport name="http"> <requestFlow> <handler type="URLMapper" /> </requestFlow> </transport> </deployment>
web.xml需要增加:
<!-- Spring MVC配置 --> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 可以自定义servlet.xml配置文件的位置和名称,默认为WEB-INF目录下,名称为[<servlet-name>]-servlet.xml,如spring-servlet.xml <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> 默认 </init-param> --> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!--axis 需要引入的 Servlet --> <servlet> <servlet-name>axis</servlet-name> <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>axis</servlet-name> <url-pattern>/services/*</url-pattern><!--axis 的 Web Service 的 Web 发布路径 --> </servlet-mapping>
webservice类:
package test; public class HelloWorldWebService implements HelloWorldRemote { //private HelloWorldRemote helloWorld; protected void onInit() throws Exception { } public String getMessage(String name) { return "xxxx"; // 在 Spring 容器中获取 Bean 的实例 //helloWorld = (HelloWorldRemote) SpringUtil.getBean("myHelloWorldBean"); // 执行 Bean 中的相同的方法 //String msg=helloWorld.getMessage(name); //return msg; } } package test; //Spring 工程中要使用的接口文件 public interface HelloWorldRemote { public String getMessage(String name); }
部署到tomcat,浏览器访问:http://localhost:8080/front/services/myWebService?wsdl
front是指项目名,可由mavn的pom或者eclipse的项目属性指定。
一切正常的话(这种概率非常小,很可能在启动时就出现了一些错误。缺少类什么了。)可以看到如下代码:
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://192.168.1.6:8080/front/services/myWebService" xmlns:intf="http://192.168.1.6:8080/front/services/myWebService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://192.168.1.6:8080/front/services/myWebService"> <!-- WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT) --> <wsdl:message name="getMessageRequest"> <wsdl:part name="name" type="soapenc:string"></wsdl:part> </wsdl:message> <wsdl:message name="getMessageResponse"> <wsdl:part name="getMessageReturn" type="soapenc:string"></wsdl:part> </wsdl:message> <wsdl:portType name="HelloWorldWebService"> <wsdl:operation name="getMessage" parameterOrder="name"> <wsdl:input message="impl:getMessageRequest" name="getMessageRequest"></wsdl:input> <wsdl:output message="impl:getMessageResponse" name="getMessageResponse"></wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="myWebServiceSoapBinding" type="impl:HelloWorldWebService"> <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getMessage"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="getMessageRequest"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://test" use="encoded"/> </wsdl:input> <wsdl:output name="getMessageResponse"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://192.168.1.6:8080/front/services/myWebService" use="encoded"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="HelloWorldWebServiceService"> <wsdl:port binding="impl:myWebServiceSoapBinding" name="myWebService"> <wsdlsoap:address location="http://192.168.1.6:8080/front/services/myWebService"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
客户端:
package test.axis14; import java.net.MalformedURLException; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import org.apache.axis.client.Call; import org.apache.axis.client.Service; public class AxisClient { public static void main(String[] args) { //String endPoint = "http://127.0.0.1:8081/axis/services/SCService?wsdl"; String endPoint = "http://127.0.0.1:8080/front/services/myWebService?wsdl"; String operation = "getMessage";// Service service = new Service(); String result = ""; try { Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL(endPoint)); call.setOperationName(operation); //ִ result = (String) call.invoke(new Object[] { " 1" }); System.out.println(result); } catch (ServiceException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } } }
参考:http://blog.csdn.net/thinker28754/article/details/2318236
http://www.ibm.com/developerworks/library/ws-whichwsdl/index.html
http://axis.apache.org/axis/java/index.html
相关推荐
maven模块项目源码demo,eclipse导入maven项目即可。 整合spring+springmvc+mybatis。压缩包中包含项目整合说明。和打包说明。 新手学习,不足指出请指出~谢谢。
Maven整合Spring+SpringMVC+Hibernate+SpringDataJPA
springmvc + spring + mybatis + maven整合配置文件
基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis...
Maven 项目 springMVC_Mybatis_Axis2_Task 整合 包含 源码 相关jar 包
spring boot 框架搭建 maven项目
1、设计数据库:设计好表结构,最好符合3NF,使用Generator自动生成Mybatis相关表信息 2、创建Maven项目,按需映入Maven包依赖-->配置文件:pom.xml 3、搭建Spring配置:spring.xml(扫描service),config....
使用Maven整合Kafka 包括生产者,消费者 Kafka各种配置 //1.设置参数 Properties props = new Properties(); props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "81.68.232.188:9092,81.68.232.188:9093,81...
整合项目,省的每次自己去整合SprinuagMvc的开发环境。
cxf spring maven 实例 webservice
这是用maven,spring,mybatis整合的一个项目,只是在下边spring,mybatis项目整合的基础上加入了maven,如果你有需要可以下下来看看,在我百度空间里有关于这个的介绍 地址:...
在一个项目中使用多个模块的一个方法是将模块添加为依赖项,正常情况下,我们会添加一个外部模块作为依赖 工程由Eclipse环境导入,我用的Eclipse4.7 主工程shushuang-project 子WEB工程shuang-project-web 公共工程...
Spring+SpringMVC+Hibernate+maven项目,适用初学者学习。
maven spring spring mvc mybatis 整合
maven spring springmvc mybatis bootstrap oracle 整合项目
使用maven构建项目,spring mvc,spring,分别与jdbctemplate,hibernate,mybatis全注解整合,其中包括包含有spring动态代理,数据库的事务处理。以及动态数据源的切换! 最新新增了ehcache缓存的应用
maven整合spring+hibernate+struts2
一、Idea关联的maven本地仓库配置...三、3个可单独使用的,maven项目文件pom.xml自定义配置 pom-maven-springboot-CusConfigV1.xml pom-maven-springboot-CusConfigV2.xml pom-maven-spring-CusConfigV1不推荐使用.xml
spring+maven整合
spring+springMVC+myBatis+maven项目整合,里面的测试demo可以直接部署在服务器上进行测试。