vb.net审批流 vbnet process( 二 )


启动Visual Studio Net
选择菜单「文件」|「新建」|「项目」后 弹出「新建项目」对话框
将「项目类型」设置为「Visual Basic项目」
将「模板」设置为「ASP NET Web 服务」
在「位置」的文本框中输入//localhost/UpdateDataWebService 后 单击「确定」按钮 这样在Visual Studio Net就会计算机Internet信息服务的默认目录中创建一个名称为 UpdateDataWebService 文件夹 里面存放的是此项目的文件 具体如图 所示
图 创建Web Service项目对话框
选中「解决方案资源管理器」中的 Service a *** x 文件 单击鼠标右键 在弹出的菜单中选择「查看代码」 则进入Service a *** x vb的编辑界面
在Service a *** x……vb的首部 在导入命名空间的代码区中添加下列代码 下列代码作用是导入命名空间System Data SqlClient
Imports System Data SqlClient
在Service a *** x……vb文件的 Public Class Service Inherits System Web Services WebService 代码后 添加下列代码 下列代码是在Web Service中定义二个功能调用
WebMethod ( )Public Function Binding ( ) As DataSet 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 dsEnd FunctionWebMethod ( )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 dsEnd Function
保存上述的修改 一个简单的操作Sql Server数据库的Web Service就完成了 此时单击快捷键F 此Web Service就开始运行 并可以对外提供服务了 具体如图 所示:
图 :Web Service提供服务是的界面
Service a *** x vb的代码清单如下:
Imports System Web ServicesImports System Data SqlClientWebService ( Namespace := )_Public Class Service Inherits System Web Services WebServiceWebMethod ( )Public Function Binding ( ) As DataSet Modify this Connection string to use your SQL Server and log onDim 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 dsEnd FunctionWebMethod ( )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 dsEnd Function#Region Web 服务设计器生成的代码 Public Sub New ( ) MyBase New ( )该调用是 Web 服务设计器所必需的InitializeComponent ( )在 InitializeComponent ( ) 调用之后添加您自己的初始化代码End Sub Web 服务设计器所必需的Private ponents As System ComponentModel IContainer注意 以下过程是 Web 服务设计器所必需的可以使用 Web 服务设计器修改此过程不要使用代码编辑器修改它System Diagnostics DebuggerStepThrough ( )Private Sub InitializeComponent ( ) ponents = New System ComponentModel Container ( )End SubProtected Overloads Overrides Sub Dispose ( ByVal disposing As Boolean ) CODEGEN: 此过程是 Web 服务设计器所必需的 不要使用代码编辑器修改它 If disposing Then If Not ( ponents Is Nothing ) Thenponents Dispose ( ) End IfEnd IfMyBase Dispose ( disposing )End Sub#End Region Web 服务示例 HelloWorld ( ) 示例服务返回字符串 Hello World 若要生成项目 请取消注释以下行 然后保存并生成项目 若要测试此 Web 服务 请确保 a *** x 文件为起始页 并按 F 键 WebMethod ( )Public Function HelloWorld ( ) As String HelloWorld = Hello World End FunctionEnd Class

推荐阅读