歡迎您光臨本站 註冊首頁

· Web Service雜誌閱讀

Web Service 例項

admin @ 2020-04-21 reply:0

Web Services 的建立與程式語言的種類無關。 此文件是一個 .asmx 檔案。這是用於 XML Web Services 的 ASP.NET 副檔名。 在這個例子中,我們會使用 ASP.NET 來建立一個簡單的 Web Service。 要執行這個例子,我們需要一個 .NET 伺服器 此文件中第一行表明這是一個 Web Service,由 VB 編寫,其 class 名稱是 "TempConvert"。

<%@ webservice="" language="VB" class="TempConvert"> 接下來的程式碼行從 .NET 框架匯入了名稱空間 "System.Web.Services"。 Imports System Imports System.Web.Services 下面這一行定義 "TempConvert" 類是一個 WebSerivce 類: Public Class TempConvert :Inherits WebService 接下來的步驟是基礎的 VB 程式設計。此應用程式有兩個函式。一個把華氏度轉換為攝氏度,而另一個把攝氏度轉換為華氏度。 與普通的應用程式唯一的不同是,此函式被定義為 "WebMethod"。 請在您希望其成為 web services 的應用程式中使用 "WebMethod" 來標記函式。

Public Function FahrenheitToCelsius (ByVal Fahrenheit As Int16) As Int16 Dim celsius As Int16 celsius = ((((Fahrenheit) - 32) / 9) * 5) Return celsius End FunctionPublic Function CelsiusToFahrenheit (ByVal Celsius As Int16) As Int16 Dim fahrenheit As Int16 fahrenheit = ((((Celsius) * 9) / 5) + 32) Return fahrenheit End Function 最後要做的事情是終止函式和類: End Function End Class 假如您把此檔案另存為 .asmx 檔案,併釋出於支援 .NET 的伺服器上,那么您就擁有了第一個可工作的 Web Service。

[admin via ] Web Service 例項已經有425次圍觀

http://coctec.com/magazine/show-post-item-111.html