1. 程式人生 > >基於Axis1.4的webservice接口開發(代碼開發)

基於Axis1.4的webservice接口開發(代碼開發)

-c oba config soap blog schema vid hand lock

基於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接口開發(代碼開發)