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

Web Service 實(shí)例

任何應(yīng)用程序都可擁有 Web Service 組件。

Web Services 的創(chuàng)建與編程語(yǔ)言的種類(lèi)無(wú)關(guān)。

一個(gè)實(shí)例:ASP.NET Web Service

在這個(gè)例子中,我們會(huì)使用 ASP.NET 來(lái)創(chuàng)建一個(gè)簡(jiǎn)單的 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

此文檔是一個(gè) .asmx 文件。這是用于 XML Web Services 的 ASP.NET 文件擴(kuò)展名。

要運(yùn)行這個(gè)例子,我們需要一個(gè) .NET 服務(wù)器

此文檔中第一行表明這是一個(gè) Web Service,由 VB 編寫(xiě),其 class 名稱(chēng)是 "TempConvert"。

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

接下來(lái)的代碼行從 .NET 框架導(dǎo)入了命名空間 "System.Web.Services"。

Imports System
Imports System.Web.Services

下面這一行定義 "TempConvert" 類(lèi)是一個(gè) WebSerivce 類(lèi):

Public Class TempConvert :Inherits WebService

接下來(lái)的步驟是基礎(chǔ)的 VB 編程。此應(yīng)用程序有兩個(gè)函數(shù)。一個(gè)把華氏度轉(zhuǎn)換為攝氏度,而另一個(gè)把攝氏度轉(zhuǎn)換為華氏度。

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

請(qǐng)?jiān)谀M涑蔀?web services 的應(yīng)用程序中使用 "WebMethod" 來(lái)標(biāo)記函數(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ù)和類(lèi):

End Function

End Class

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

ASP.NET 的自動(dòng)化處理

通過(guò) ASP.NET,你不必親自編寫(xiě) WSDL 和 SOAP 文檔。

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

馆陶县| 渭源县| 西峡县| 珲春市| 台前县| 巢湖市| 庄河市| 深水埗区| 永城市| 商河县| 双峰县| 廉江市| 会泽县| 武隆县| 台山市| 盐城市| 丰台区| 剑阁县| 南城县| 海宁市| 葵青区| 郎溪县| 米泉市| 峡江县| 昌图县| 德格县| 奉贤区| 龙门县| 满洲里市| 盐亭县| 内丘县| 栖霞市| 金平| 德昌县| 大化| 象州县| 繁峙县| 桂阳县| 同心县| 黄骅市| 凤台县|