●使用.NET建立Web Services
1. 開啟.Net,建立「ASP.NET Web Services應用程式」專案。
2. 範例程式碼如下:
Imports System.Web.Services ' 若要允許使用 ASP.NET AJAX 從指令碼呼叫此 Web 服務,請取消註解下一行。 <WebMethod()> _ End Class |
需把web.config中的<add name="ScriptModule" ...>給註解掉。
3. 看到如下的畫面就表示成功了!比起Java,用.NET只能說是小菜一碟。
●使用.NET建立Web Services Client呼叫.NET建立的Web Services
在「方案總管」中的「Web References」按右鍵選取「加入Web參考」,再選擇要用哪一個Web Services,可直接鍵入asmx的網址。
亦需把web.config中的<add name="ScriptModule" ...>註解掉
修改程式碼,此範例為直接給Web services值,再顯示在畫面上。
Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
●使用Java建立Web Services Client呼叫.NET建立的Web Services
新增一Dynamic Project,wsclient。在wsclient專案上按右鍵新增Web Service Client。
在Service definition輸入WSDL的網址。
在wsclient專案下新增一檔案ws.java
package org.tempuri;
public class ws { public static void main(String[] args) { } |
恭喜大功告成!