扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:马金虎 来源:天极开发 2007年11月9日
关键字:
图01:创建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 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 |
图02:Web Service提供服务是的界面 |
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 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者