我想要从 Web 服务内的数据集检索数据到我的 Windows 窗体,然后将数据从我的 Windows 窗体发送到 Web 服务。
我定义了一个函数,该函数返回我的 asmx 文件中的类内的数据集:
Public Class DataSetWebService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetUsers() As DataSet
Dim cn As SqlConnection = New SqlConnection("Data Source=.;Initial Catalog=WebServiceTest;Integrated Security=SSPI")
Dim cm As SqlCommand : Dim ds As New DataSet : Dim da As SqlDataAdapter : Dim str As String
Try
str = "Select * from User_Table"
If cn.State = ConnectionState.Closed Then cn.Open()
cm = New SqlCommand(str, cn)
da = New SqlDataAdapter(cm)
da.Fill(ds)
return ds
Catch ex As SqlException
Catch ex As Exception
Finally
If cn.State = ConnectionState.Open Then cn.Close()
End Try
End Function
End Class
在我的 Windows 窗体中,我编写了以下代码:
Dim ws As New UserService.DataSetWebService()
但它说“DataSetWebService() 未定义”
最佳答案
您需要将服务方法定义为共享。像这样
Public Shared Function GetUsers() As DataSet
然后“添加 Web 引用”到您的 Windows 应用程序。
希望它能解决您的问题。
关于vb.net - 将数据集从 asmx 文件返回到 Windows 窗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18785313/