最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Web Service 實例

任何應用程序都可擁有 Web Service 組件。

Web Services 的創(chuàng)建與編程語言的種類無關。

一個實例:ASP.NET Web Service

在這個例子中,我們會使用 ASP.NET 來創(chuàng)建一個簡單的 Web Service。

<%@ WebService Language="VB" Class="TempConvert" %>

Imports System
Imports System.Web.Services


Public Class TempConvert :Inherits WebService

<WebMethod()> Public Function FahrenheitToCelsius
(ByVal Fahrenheit As Int16) As Int16
	Dim celsius As Int16 
	celsius = ((((Fahrenheit) - 32) / 9) * 5) 
	Return celsius
End Function

<WebMethod()> Public Function CelsiusToFahrenheit
(ByVal Celsius As Int16) As Int16
	Dim fahrenheit As Int16
	fahrenheit = ((((Celsius) * 9) / 5) + 32) 
	Return fahrenheit
End Function
End Class

此文檔是一個 .asmx 文件。這是用于 XML Web Services 的 ASP.NET 文件擴展名。

要運行這個例子,我們需要一個 .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 編程。此應用程序有兩個函數(shù)。一個把華氏度轉換為攝氏度,而另一個把攝氏度轉換為華氏度。

與普通的應用程序唯一的不同是,此函數(shù)被定義為 "WebMethod"。

請在您希望其成為 web services 的應用程序中使用 "WebMethod" 來標記函數(shù)。

<WebMethod()> Public Function FahrenheitToCelsius
(ByVal Fahrenheit As Int16) As Int16
	Dim celsius As Int16 
	celsius = ((((Fahrenheit) - 32) / 9) * 5) 
	Return celsius
End Function

<WebMethod()> Public Function CelsiusToFahrenheit
(ByVal Celsius As Int16) As Int16
	Dim fahrenheit As Int16
	fahrenheit = ((((Celsius) * 9) / 5) + 32) 
	Return fahrenheit
End Function

最后要做的事情是終止函數(shù)和類:

End Function

End Class

假如您把此文件另存為 .asmx 文件,并發(fā)布于支持 .NET 的服務器上,那么您就擁有了第一個可工作的 Web Service。

ASP.NET 的自動化處理

通過 ASP.NET,你不必親自編寫 WSDL 和 SOAP 文檔。

如果您仔細研究我們的這個例子,您會發(fā)現(xiàn) ASP.NET 會自動創(chuàng)建 WSDL 和 SOAP 請求。

湄潭县| 甘孜县| 辽宁省| 乡宁县| 伊春市| 永新县| 马公市| 铜陵市| 高雄县| 福安市| 盐边县| 易门县| 常州市| 宜丰县| 肇庆市| 西畴县| 蓝田县| 鄯善县| 芒康县| 双柏县| 巴林右旗| 新乐市| 玛纳斯县| 封开县| 临汾市| 玉溪市| 彩票| 彭阳县| 临高县| 钟祥市| 建德市| 当涂县| 东平县| 称多县| 丽水市| 定结县| 延寿县| 荔浦县| 甘泉县| 双牌县| 马边|