CTOCIO IT专家网

天极传媒 比特网 | 天极网 | IT专家网 | IT商网 | 52PK游戏网 | 手机天极 | IT分众 |
IT专家网搜索

您现在的位置: IT专家网 > Web服务子站 > 技巧

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

作者: ,  出处:天极, 责任编辑: 叶江, 
2005-12-09 11:00
  Web Service目前可是目前计算机界一个非常流行的技术了,以至于有些人把Web Service列入目前最热门的十大技术之一。本文的主要内容是简要介绍一下Web Service的相关知识,以及使用Visual Basic .Net实现Web Services的具体方法和典型步骤。

  13. Form1.vb的代码清单如下:

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New ( )
 MyBase.New ( )
 '该调用是 Windows 窗体设计器所必需的。
 InitializeComponent ( )
 '在 InitializeComponent ( ) 调用之后添加任何初始化
End Sub
'窗体重写处置以清理组件列表。
Protected Overloads Overrides Sub Dispose ( ByVal disposing As Boolean )
 If disposing Then
  If Not ( components Is Nothing ) Then
   components.Dispose ( )
  End If
 End If
 MyBase.Dispose ( disposing )
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
 '注意:以下过程是 Windows 窗体设计器所必需的
 '可以使用 Windows 窗体设计器修改此过程。
 '不要使用代码编辑器修改它。
 Friend WithEvents Button1 As System.Windows.Forms.Button
 Friend WithEvents Button2 As System.Windows.Forms.Button
 Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
 <System.Diagnostics.DebuggerStepThrough ( ) > Private Sub InitializeComponent ( )
 Me.Button1 = New System.Windows.Forms.Button ( )
 Me.Button2 = New System.Windows.Forms.Button ( )
 Me.DataGrid1 = New System.Windows.Forms.DataGrid ( )
 CType ( Me.DataGrid1 , System.ComponentModel.ISupportInitialize ) .BeginInit ( )
 Me.SuspendLayout ( )
 Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
 Me.Button1.Location = New System.Drawing.Point ( 56 , 216 )
 Me.Button1.Name = "Button1"
 Me.Button1.Size = New System.Drawing.Size ( 75 , 32 )
 Me.Button1.TabIndex = 0
 Me.Button1.Text = "绑定"
 Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat
 Me.Button2.Location = New System.Drawing.Point ( 168 , 216 )
 Me.Button2.Name = "Button2"
 Me.Button2.Size = New System.Drawing.Size ( 75 , 32 )
 Me.Button2.TabIndex = 1
 Me.Button2.Text = "修改"
 Me.DataGrid1.DataMember = ""
 Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Top
 Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
 Me.DataGrid1.Name = "DataGrid1"
 Me.DataGrid1.Size = New System.Drawing.Size ( 292 , 192 )
 Me.DataGrid1.TabIndex = 2
 Me.AutoScaleBaseSize = New System.Drawing.Size ( 6 , 14 )
 Me.ClientSize = New System.Drawing.Size ( 292 , 273 )
 Me.Controls.AddRange ( New System.Windows.Forms.Control ( ) {Me.DataGrid1 , Me.Button2 , Me.Button1} )
 Me.Name = "Form1"
 Me.Text = "测试Web Service"
 CType ( Me.DataGrid1 , System.ComponentModel.ISupportInitialize ) .EndInit ( )
 Me.ResumeLayout ( False )
End Sub
#End Region
Private Sub Button1_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) Handles Button1.Click
 Dim MyService As New localhost.Service1 ( )
 DataGrid1.DataSource = MyService.Binding ( )
 DataGrid1.DataMember = "Cust"
End Sub
Private Sub Button2_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) Handles Button2.Click
 Dim MyService As New localhost.Service1 ( )
 Dim ds As DataSet = DataGrid1.DataSource
 Dim dsChanges As DataSet = ds.GetChanges ( )
 If Not ( dsChanges Is Nothing ) Then
  ds.Merge ( MyService.Update ( dsChanges ) , True )
 End If
End Sub
End Class

  五.总结:

  本文介绍了Web Service在目前大行其道的原因,并结合二个示例介绍Visual Basic .Net在Web Service的实现和调用上的强大功能,正如本文前面所说,Visual Studio .Net的出现使得web Service的这项原先繁杂的工作变得异常的简单,因为Visual Basic .Net已经替代我们作了这些描述性的、基础的底层工作,以至于你不需要了解为什么,只需要知道你要实现什么就可以编写、调用Web Service了。 在实现Web Service在数据库方面应用所显示

  Web Service虽然以其强大功能和其优越性正在受到越来越多人的青睐,但也不可以回避它的缺点,譬如其速度慢就使得我几乎无法忍受。等等这样的原因也决定了Web Service并不适用于所有的环境。如单机运行程序和局域网上的同构应用程序等就尽量不采用Web Service方式。本文只是展示了Visual Studio .Net在Web Service上的初步用途,至于更复杂的使用、调用方法只能在后续的文章中介绍了,感兴趣的朋友,我们下一文再见!

共6页。 9 1 2 3 4 5 6

网友评论

笔名 
请您注意:遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。    IT专家网友拥有管理笔名和留言的一切权利。
  • 周排行榜
  • 月排行榜

邮件订阅

       
天极服务 | 关于我们 | 网站律师 | 加入我们 | 联系我们 | 广告业务 | 友情链接 | 我要挑错
All Rights Reserved, Copyright 2004-2008, Ctocio.com.cn
渝ICP证B2-20030003号 如有意见请与我们联系 powered by 天极内容管理平台CMS4i