概括VB.NET創(chuàng)建WebService
VB.NET還是比較常用的,于是我研究了一下VB.NET創(chuàng)建WebService,在這里拿出來(lái)和大家分享一下,希望對(duì)大家有用。
VB.NET創(chuàng)建WebService.
具體步驟如下:
1. 新建一個(gè)項(xiàng)目,選擇ASP.NET Web服務(wù),命名為:“WebService For 業(yè)務(wù)層”。
2. 添加兩個(gè)Sql DataAdapter,一個(gè)為Customer_da,它指向NorthWind數(shù)據(jù)庫(kù)的Customers表,另一個(gè)為Order_da,指向Northwind數(shù)據(jù)庫(kù)的Orders表。
3. 然后生成一個(gè)Typed DataSet(選擇“數(shù)據(jù)”菜單的“生成數(shù)據(jù)集”),命名為:Super_ds.
4. 數(shù)據(jù)庫(kù)連接已經(jīng)完成,下一步我們將考慮它與表示層之間的通信,這里我們定義兩個(gè)方法。一個(gè)為:Get_DataSet,它返回一個(gè)Super_ds類型的數(shù)據(jù)集,另一個(gè)為:Update_DataSet,它負(fù)責(zé)更新數(shù)據(jù)庫(kù)數(shù)據(jù), 方法代碼如下:
- Public Function Get_Dataset() As super_ds
- customer_da.Fill(Super_ds1.Customers)
- order_da.Fill(Super_ds1.Orders)
- Return Super_ds1
- End Function
- Public Sub Update_Dataset()
- Super_ds1.AcceptChanges()
- End Sub
你可以運(yùn)行測(cè)試一下你的VB.NET建立WebService,它將提供兩個(gè)方法。返回的DataSet是以XML表示的。
業(yè)務(wù)層的完整代碼如下:
- Imports System.Web.Services
- Public Class Service1
- Inherits System.Web.Services.WebService
- 'Web Services Designer Generated Code……。
Public Function Get_Dataset() As super_ds - customer_da.Fill(Super_ds1.Customers)
- order_da.Fill(Super_ds1.Orders)
- Return Super_ds1
- End Function
Public Sub Update_Dataset() - Super_ds1.AcceptChanges()
- End Sub
- ' WEB SERVICE EXAMPLE
- ' The HelloWorld() example service returns the string Hello World.
- ' To build, uncomment the following lines then save and build the project.
- ' To test this web service, ensure that the .asmx file is the start page
- ' and press F5.
- '
- '
Public Function HelloWorld() As String - ' HelloWorld = "Hello World"
- ' End Function
- End Class
【編輯推薦】