<servlet>
<servlet-name>adminservlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.adminservlet
</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>adminservlet</servlet-name>
<url-pattern>/servlet/adminservlet</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>wsdl</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xsd</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
你現(xiàn)在可以在網(wǎng)址里輸入http://localhost/webservicetest/servlet/testservlet 看到了嗎?axis是使用axis.jar包里的org.apache.axis.transport.http.axisservlet對應(yīng)用程序進(jìn)行處理的,基本配置就講到這里。
三、接著我們來說axis中的內(nèi)核。
1)不使用tomcat引擎運行axis。
先建立一個腳步文件,對環(huán)境變量classpath進(jìn)行設(shè)置要把lib下的那些包文件的路徑全都包括進(jìn)去,運行:java org.apache.axis.transport.http.simpleaxisserver <port>
2)內(nèi)部服務(wù)處理程序是org.apache.axis.providers.java.rpcprovider,標(biāo)志出服務(wù)所需的方法,然后提供從soap請求消息組成部分的參數(shù)。
3)axis的應(yīng)用程序端管理功能:
java org.apache.axis.client.adminclient 就會列出參數(shù),可供你選擇。我們的例子是:java org.apache.axis.client.adminclient -l http://localhost/webservicetest/servlet/testservlet list 就會顯示出服務(wù)列表,返回的是xml文件
4)wsdl2java應(yīng)用程序可以把wsdl文件創(chuàng)建基于java的程序,如占位程序等
java org.apache.axis.wsdl.wsdl2java <url>
axis的基本內(nèi)容說到這里
四、具體例子
1)編寫邏輯程序,簡單如:soaptest.java
public class soaptest{
public string getstr(string name){
return "hello,"+name;
}
}
2) 部署服務(wù),編寫wsdd文件soaptest_deploy.wsdd:
<deployment name="simapletest" xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns:xsd="http://www.w3.org/2000/10/xmlschema"
xmlns:xsi="http://www.w3.org/2000/10/xmlschema-instance">
<service name="soaptest" provider="java:rpc">
<parameter name="classname" value="soaptest"/>
<parameter name="allowedmethods" value="getstr"/>
</service>
</deployment>
其中classname參數(shù)是你的想部署的類名(全名),allowedmethods是調(diào)用的服務(wù)的方法,如果有多個方法的話可以用空格分開(如: <parameter name="allowedmethods" value="getstr getmoney"/>),當(dāng)用*的時候表示全部。
好了現(xiàn)在準(zhǔn)備部署了,確保環(huán)境路徑classpath設(shè)置正確,運行:
java org.apache.axis.client.adminclient -l http://localhost/webservicetest/servlet/testservlet soaptest_deploy.wsdd
(這里不懂的話,請參考以上的說明)
ok,呵呵,至此,我們已經(jīng)完成了一個web服務(wù)的部署:測試http://localhost/webservicetest/servlet/testservlet 看里面是否多了一個選擇soaptest服務(wù)?
如果不想要服務(wù)了那重新編寫一個wsdd文件,內(nèi)容改為:
<deployment name="simapletest" xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns:xsd="http://www.w3.org/2000/10/xmlschema"
xmlns:xsi="http://www.w3.org/2000/10/xmlschema-instance">
<service name="soaptest"/>
</deployment>
和上面一樣,對比一下就ok了。
五、客戶端測試:
客戶端我們也可以使用java來進(jìn)行測試,網(wǎng)上也有資料的,你可以去學(xué)習(xí),很簡單的。現(xiàn)在為了體現(xiàn)web服務(wù)的魅力,我用.net平臺來測試吧,客戶端使用c#編寫(先要安裝.net framework sdk):
1)通過wsdl生成web服務(wù)代理,在net平臺下運行:
wsdl /l:cs /protocol:soap /out:soaptestclient.cs http://localhost/webservicetest/services/soaptest?wsdl
我們通過wsdl得到了一個cs文件soaptestclient.cs(當(dāng)前目錄),你可以打開cs文件,研究一下里面的代碼,那個getstr(string name)就是我們需要調(diào)用的方法,我們的客戶端通過調(diào)用該方法就可以調(diào)用服務(wù)器端的方法,內(nèi)部的轉(zhuǎn)化wsdl.exe工具已經(jīng)幫我們完成了,axis下的wsdl2java工具也是一樣的功能,可以參考我上面所說的關(guān)于axis的內(nèi)核內(nèi)容
2)編譯cs文件成程序集dll:
csc /target:library /r:system.web.services.dll /r:system.xml.dll soaptestclient.cs
最后我們等到了一個dll文件soaptestclient.dll,客戶端程序通過調(diào)用它就行了
3)編寫客戶端應(yīng)用程序soaptestclientapp.cs
using system;
namespache jws.client{
public class soaptestclientapp{
public soaptestclientapp(){
}
public static void main(string[] args){
if(args.length!=1){
console.writeline("usage:soaptestclientapp <name>");
environment.exit(1);
}
soaptestservice st_service=new soaptestservice();
st_service.getstr("wang wenyin");
}
}
}
4)編譯文件csc /r:soaptestclient.dll soaptestclientapp.cs
運行soaptestclientapp
輸出結(jié)果:
hello,wang wenyin
與預(yù)期結(jié)果相符。
好了,關(guān)于soap開發(fā)web服務(wù)就說到這里了,希望這篇文章能對大家有所幫助,謝謝了:)有問題的話可以留言,也可以跟我聯(lián)系 [email protected]
新聞熱點
疑難解答
圖片精選