System.Web.Services 无法添加到 Visual Studio 中的 VB.NET 项目中

Posted

技术标签:

【中文标题】System.Web.Services 无法添加到 Visual Studio 中的 VB.NET 项目中【英文标题】:System.Web.Services cannot be added to VB.NET project in Visual Studio 【发布时间】:2022-01-14 17:37:21 【问题描述】:

我正在使用 Windows 窗体在 Visual Studio Community 2019 中开发一个 VB.NET 项目。我想用来自 DataSet 的数据填充 DataGridView。但是在创建 DataSet 时出现错误,说“无法将 System.Web.Services 添加到项目中”。然后创建了 DataSet,但我无法选择它作为 DataGridView 的 DataSource。也许值得一提的是,我的项目并不打算处理任何在线内容,所以我想知道为什么我需要任何 Web 服务的东西。我怎样才能摆脱错误,或者至少用我的 DataSet 填充 DataGridView?

我注意到 - 感谢 Jon!- 属于 DataSet 的 VB 代码中的以下内容(大约 600 行自动生成的行):

Me.DataSetName = "DataSet1"
Me.Prefix = ""
Me.Namespace = "http://tempuri.org/DataSet1.xsd"

再往下:

Dim any1 As Global.System.Xml.Schema.XmlSchemaAny = New Global.System.Xml.Schema.XmlSchemaAny()
any1.Namespace = "http://www.w3.org/2001/XMLSchema"

我不知道如何手动将数据绑定到网格视图,我试图使用 GUI 来执行此操作,但它没有为我提供 DateSet 作为源。

对于 DataGrid 视图,我将它从工具箱中拖入其中,可以在“所有 Windows 窗体”->“DataGridView”下找到它。

【问题讨论】:

确保您没有尝试使用 WebForms Gridview 控件。向我们展示您在哪里创建数据集并尝试绑定到 DataGridView 的代码 我现在通过创建一个可以作为数据集加载的 xml 来解决它:dim xmlfile as XmlReader ds=new DataSet ds.ReadXml(xmlfile) DataGridView1.DataSource = ds.Table(0) @pantha-rhey 您可以通过发布答案来分享您的解决方案,然后接受它,以便其他有类似问题的成员可以快速找到解决方案。 【参考方案1】:

现在围绕着创建数据集的 GUI 方式工作

创建一个可以作为数据集加载的 xml
<NewDataSet>
<Table0><col0>entry0row0</col0><col1>entry1row0</col1></Table0>
<Table0><col0>entry0row1</col0><col1>entry1row1</col1></Table0>
</NewDataSet>
通过以下方式读取 xml:
Imports System.xml

ds = New DataSet
Using xmlFile As XmlReader = XmlReader.Create(filename, New XmlReaderSettings())
ds.ReadXml(xmlFile)
End Using
DataGridView1.DataSource = ds.Table(0)

【讨论】:

以上是关于System.Web.Services 无法添加到 Visual Studio 中的 VB.NET 项目中的主要内容,如果未能解决你的问题,请参考以下文章

Visual Studio/SOAP -“添加服务引用”与“添加 Web 服务引用”

System.Web.Services.Protocols.SoapException: 服务器未能识别 HTTP 头 SOAPAction 的值,此问题如何解决

如何在 web 方法中访问会话?

系统环境存在啥问题么,报错如下:System.Web.Services.Protocols.SoapException: Object of type 'c__

如何将 WS-Addressing 字段添加到 SOAP 消息

.NET Web 服务超时异常