标签:sha 1.0 用户 clip net ssi images method tar
基于Axis1.4的webservice接口开发(代码开发)
一、开发环境:
我的开发环境是MyEclipse 2015+Apache-Tomcat-8.0.21。
二、代码开发:
1、新建一个Web Project工程,并导入jar包(Axis1.4的环境搭建在上一篇博客http://www.cnblogs.com/zhukunqiang/p/7124977.html中有介绍):
1、在com.ll.server包下新建java类,工程结构目录如下:
2、java代码如下(由于该项目用于测试,简单点无所谓):
package com.ll.server; public class HelloWorld { public String sayHello(String username){ return spake()+"hello, " + username; } public String spake(){ return "调用了HelloWorld类的spake方法"; } }
4、配置web.xml文件:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>axiswebservice</display-name> <servlet> <servlet-name>AxisServlet</servlet-name> <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
5、在工程的WEB-INF目录下新建deploy.wsdd文件,文件内容如下:
<?xml version="1.0"encoding="UTF-8"?> <deployment xmlns="http:/xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <!-- service标签代表一个WebService服务 --> <service name="HelloWorld" provider="java:RPC"> <!-- 命名空间,使用wsdl2java生成客户端代码时,包路径为:com.ll.server --> <!-- 假如发布服务地址为:http://localhost:8080/axiswebservice/services/HelloWorld --> <!-- 如果属性wsdlTargetNamespace不设置的话,生成客户端代码的默认包路径为:localhost.axiswebservice.services --> <parameter name="wsdlTargetNamespace" value="http://server.ll.com" /> <parameter name="wsdlServicePort" value="HelloWorld" /> <!-- 服务类路径 --> <parameter name="className" value="com.ll.server.HelloWorld" /> <!-- * 代表所有的方法都暴露 --> <parameter name="allowedMethods" value="*" /> <!-- 当前WebService的作用域,它有3个值,分别是:request每个请求、session每个用户、application所有请求 --> <parameter name="scope" value="request" /> </service> </deployment>
6、在工程的WEB-INF目录下新建server-config.wsdd文件,文件内容如下:
<?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <globalConfiguration> <!-- 变量设定 --> <parameter name="sendMultiRefs" value="true" /> <parameter name="disablePrettyXML" value="true" /> <parameter name="adminPassword" value="admin" /> <parameter name="attachments.Directory" value="D:\office path\Apache-Tomcat-8.0.21\webapps\axis\WEB-INF\attachments" /> <parameter name="dotNetSoapEncFix" value="true" /> <parameter name="enableNamespacePrefixOptimization" value="true" /> <parameter name="sendXMLDeclaration" value="true" /> <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl" /> <parameter name="sendXsiTypes" value="true" /> <requestFlow> <handler type="java:org.apache.axis.handlers.JWSHandler"> <parameter name="scope" value="session" /> </handler> <handler type="java:org.apache.axis.handlers.JWSHandler"> <parameter name="scope" value="request" /> <parameter name="extension" value=".jwr" /> </handler> </requestFlow> </globalConfiguration> <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder" /> <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" /> <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" /> <!-- 核心重点:服务发布,name:表示发布的service名 --> <service name="HelloWorld" provider="java:RPC"> <!-- 发布的service接口类 --> <parameter name="className" value="com.ll.server.HelloWorld" /> </service> <transport name="http"> <requestFlow> <handler type="URLMapper" /> <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" /> </requestFlow> <parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler" /> <parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler" /> <parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler" /> <parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler" /> <parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler" /> <parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler" /> </transport> <transport name="local"> <responseFlow> <handler type="LocalResponder" /> </responseFlow> </transport> </deployment>
三、原项目测试:
1、将项目部署到Tomcat中,并启动服务器。
2、在浏览器地址栏输入:http://localhost:8080/axiswebservice/services/HelloWorld得到如下界面:
3、在浏览器地址栏输入:http://localhost:8080/axiswebservice/services/HelloWorld?wsdl得到如下界面:
如果输入网址,出现2、3步所示的界面,则webservice接口部署成功。
基于Axis1.4的webservice接口开发的接口调用部分在下一篇中会有介绍:http://www.cnblogs.com/zhukunqiang/p/7125691.html
基于Axis1.4的webservice接口开发(代码开发)
标签:sha 1.0 用户 clip net ssi images method tar
原文地址:http://www.cnblogs.com/zhukunqiang/p/7125668.html