正 文

VB.Net编程实现Web Service的基础


www.7dspace.com  更新日期:2005-12-10 1:49:39  七度空间



  9. 保存上述的修改,一个简单的操作Sql Server数据库的Web Service就完成了,此时单击快捷键F5,此Web Service就开始运行,并可以对外提供服务了。具体如图02所示:


图02:Web Service提供服务是的界面

  Service1.asmx.vb的代码清单如下:

Imports System.Web.Services
Imports System.Data.SqlClient
<WebService ( Namespace := "http://tempuri.org/" ) > _
Public Class Service1
Inherits System.Web.Services.WebService
<WebMethod ( ) > Public Function Binding ( ) As DataSet
'Modify this Connection string to use your SQL Server and log on.
 Dim con As New SqlConnection ( "Server=localhost;uid=sa;pwd=;database=northwind" )
 Dim daCust As New SqlDataAdapter ( "Select * From Customers" , con )
 Dim ds As New DataSet ( )
 daCust.Fill ( ds , "Cust" )
 Return ds
End Function
<WebMethod ( ) > Public Function Update ( ByVal ds As DataSet ) As DataSet
 Dim con As New SqlConnection ( "Server=localhost;uid=sa;pwd=;database=northwind" )
 Dim daCust As New SqlDataAdapter ( "Select * From Customers" , con )
 Dim cbCust As New SqlCommandBuilder ( daCust )
 daCust.Update ( ds , "Cust" )
 Return ds
End Function
#Region " Web 服务设计器生成的代码 "
Public Sub New ( )
 MyBase.New ( )
 '该调用是 Web 服务设计器所必需的。
 InitializeComponent ( )
 '在 InitializeComponent ( ) 调用之后添加您自己的初始化代码
End Sub
'Web 服务设计器所必需的
Private components As System.ComponentModel.IContainer
 '注意:以下过程是 Web 服务设计器所必需的
 '可以使用 Web 服务设计器修改此过程。
 '不要使用代码编辑器修改它。
 <System.Diagnostics.DebuggerStepThrough ( ) > Private Sub InitializeComponent ( )
 components = New System.ComponentModel.Container ( )
End Sub
Protected Overloads Overrides Sub Dispose ( ByVal disposing As Boolean )
'CODEGEN: 此过程是 Web 服务设计器所必需的
'不要使用代码编辑器修改它。
If disposing Then
 If Not ( components Is Nothing ) Then
  components.Dispose ( )
 End If
End If
MyBase.Dispose ( disposing )
End Sub
#End Region
' Web 服务示例
' HelloWorld ( ) 示例服务返回字符串 Hello World。
' 若要生成项目,请取消注释以下行,然后保存并生成项目。
' 若要测试此 Web 服务,请确保 .asmx 文件为起始页
' 并按 F5 键。
'
'<WebMethod ( ) > Public Function HelloWorld ( ) As String
' HelloWorld = "Hello World"
' End Function
End Class

  下面就来介绍Visual Basic .Net中使用这个Web Service提供的服务来更新数据库的实现方法。
6页,页码:[1] [2] [3] [4] [5] [6] 

上一篇:Flash版在线Google talk火辣尝鲜!
下一篇:Eclipse 3.1中的Java泛型支持
作者:马金虎  来源:天极网 ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐