【摘 要】Axis本質(zhì)上就是一個SOAP引擎,提供創(chuàng)建服務器端、客戶端和網(wǎng)關SOAP操作的基本框架。Axis目前版本是為Java編寫的,不過為C++的版本正在開發(fā)中。

 什么是SOAP?

  SOAP是一個基于XML的用于應用程序之間通信數(shù)據(jù)編碼的傳輸協(xié)議。最初由微軟和Userland Software提出,隨著不斷地完善和改進,SOAP很快被業(yè)界廣泛應用。

  什么是Axis?

  Axis本質(zhì)上就是一個SOAP引擎,提供創(chuàng)建服務器端、客戶端和網(wǎng)關SOAP操作的基本框架。Axis目前版本是為Java編寫的,不過為C++的版本正在開發(fā)中。

  配置webservice具體步驟:

  1.安裝weblogic。

  2.配置一個web應用,如“\\lijunjie\e$\software\bea\user_projects\domains\lijjdomain\applications\ cntapws “。

  3.從apache網(wǎng)站上下載axis-bin-1_2_1.tar.gz,解壓后copy到cntapws下面。

  4.打開“http://localhost:7001/console“,配置cntapws 的web應用。

  5.axis1.2和weblogic8.1有沖突,原因是weblogic 本身攜帶的webservice.jar使用的舊的javax.xml.soap.*,而不是像axis使用J2EE1.4新的版本。解決方案是在WEB -INF/weblogic.xml文件中如下的配置:

<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>

  6.按 http://localhost:8080/axis/happyaxis.jsp地址,可以顯示你發(fā)布的webservice是否配置成功,如果顯示必須的包缺失,則你的webservice不能正常運行。

  開發(fā)webservice流程

  1.寫普通的java類,該類中有你要發(fā)布到webservice上的有關方法。

  2.配置server-comfig.xml, 把你要發(fā)布的方法寫入該文件。具體內(nèi)容如下:

<?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="adminPassword" value="admin"/>

<parameter name="attachments.Directory" value="C:\eclipse\workspace\bookstore\WEB-INF\attachments"/>

<parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>

<parameter name="sendXsiTypes" value="true"/>

<parameter name="sendMultiRefs" value="true"/>

<parameter name="sendXMLDeclaration" value="true"/>

<parameter name="axis.sendMinimizedElements" 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="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>

<handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>

<service name="Version" provider="java:RPC">

<parameter name="allowedMethods" value="getVersion"/>

<parameter name="className" value="org.apache.axis.Version"/>

</service>

<!--要配置的內(nèi)容start,注意每一個要發(fā)布成webservice的類都要配置成一個service如下à

<service name="webserviceproxy" provider="java:RPC">

<parameter name="className" value="com.copia.webservice.server.proxy.WebServiceProxy"/>

<parameter name="allowedMethods" value="*"/>

<!—具體某個方法說明-->

<operation name="login" returnType="ns:LoginOutServiceBean">

<parameter name="branchNo" type="xsd:string"/>

<parameter name="userId" type="xsd:string"/>

<parameter name="password" type="xsd:string"/>

<parameter name="certificateNo" type="xsd:string"/>

</operation>

<!—如果該方法的參數(shù)有基本類型和對象類型,則不要聲明,webservice能夠找到相關的類及方法-->

<!—聲明涉及到的所有類及其父類,引用類,還有它們的相關類,類似與對象樹遍歷,某個類聲明缺失也會導致運行失敗-->

<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

qname="ns:LoginOutServiceBean"

serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

type="java:com.copia.core.module.security.login.LoginOutServiceBean" xmlns:ns="webserviceproxy"/>

<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

qname="ns:User"

serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

type="java:com.copia.core.client.User" xmlns:ns="webserviceproxy"/>

<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

qname="ns:GetBatchListInServiceBean"

serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

type="java:com.copia.core.module.batch.service.GetBatchListInServiceBean" xmlns:ns="webserviceproxy"/>

<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

qname="ns:GetBatchListOutServiceBean"

serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

type="java:com.copia.core.module.batch.service.GetBatchListOutServiceBean" xmlns:ns="webserviceproxy"/>

<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

qname="ns:BatchJobDefBean"

serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

type="java:com.copia.core.module.batch.service.BatchJobDefBean" xmlns:ns="webserviceproxy"/>

<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

qname="ns:ValueObjectPage"

serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

type="java:com.copia.core.voa.ValueObjectPage" xmlns:ns="webserviceproxy"/>

<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

qname="ns:ValueObjectColInfo"

serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

type="java:com.copia.core.voa.ValueObjectColInfo" xmlns:ns="webserviceproxy"/>

<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

qname="ns:ValueObjectList"

serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

type="java:com.copia.core.voa.ValueObjectList" xmlns:ns="webserviceproxy"/>

<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

qname="ns:PageInfo"

serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

type="java:com.copia.core.voa.PageInfo" xmlns:ns="webserviceproxy"/>

<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

qname="ns:ValueObjectMetaData"

serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

type="java:com.copia.core.voa.ValueObjectMetaData" xmlns:ns="webserviceproxy"/>

</service>

<!--要配置的內(nèi)容endà

<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>

<transport name="local">

<responseFlow>

<handler type="LocalResponder"/>

</responseFlow>

</transport>

<transport name="http">

<requestFlow>

<handler type="URLMapper"/>

<handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>

</requestFlow>

</transport>

</deployment>

  3.在地址欄輸入http://localhost:7001/cntapws/services/webserviceproxy?wsdl,如沒有什么錯誤,則表示你的webservice發(fā)布成功了。

  Java webservice客戶端編程

  1.啟動你配置好的weblobic。

  2.進入dos界面,在你的臨時目錄(任意目錄)下根據(jù)wsdl產(chǎn)生客戶文件,如下指令:

E:\kk>java -Djava.ext.dirs=E:\software\bea\user_projects\domains\lijjdomain\appl

ications\axis\WEB-INF\axislib org.apache.axis.wsdl.WSDL2Java http://localhost:7001/cntapws/services/webserviceproxy?wsdl即可在kk目錄下產(chǎn)生有關文件。

  3.把產(chǎn)生的文件copy到你的工程中,再寫一個webservice調(diào)用測試類,如下:

public class TestWs {

public static void main(String[] args) {

WebServiceProxyService service = new WebServiceProxyServiceLocator();

try {

WebServiceProxy serviceProxy = service.getwebserviceproxy();

User user = new User();

user.setBranchNo("000001");

user.setClerkNo("1004");

GetBatchListInServiceBean in = new GetBatchListInServiceBean();

in.setCurPageNo(1);

String serviceName = "GetBatchListService";

GetBatchListOutServiceBean out = (GetBatchListOutServiceBean)serviceProxy.getBatchListService(user, in, serviceName);

BatchJobDefBean[] defBeans = out.getBatchJobDefBeans();

for(int i = 0 ; i < defBeans.length ; i++){

System.out.println(defBeans[i].getBatchName());

}

}catch(Exception ex){

ex.printStackTrace();

}

}

}