向项目添加对 Web 服务的引用。 将向项目的“Web 引用”文件夹添加新的 Web 服务引用子文件夹。 该新文件夹包含与该 Web 服务相关的若干其他项目项。 该方法返回与新的“Web 服务”文件夹关联的 ProjectItem 对象。
命名空间:  VSLangProj
程序集:  VSLangProj(在 VSLangProj.dll 中)
语法
声明
Function AddWebReference ( _
    bstrUrl As String _
) As ProjectItem
ProjectItem AddWebReference(
    string bstrUrl
)
ProjectItem^ AddWebReference(
    [InAttribute] String^ bstrUrl
)
abstract AddWebReference : 
        bstrUrl:string -> ProjectItem 
function AddWebReference(
    bstrUrl : String
) : ProjectItem
参数
- bstrUrl
 类型:System.String
 必选。通常,这是带有 .disco 或 .vsdisco 扩展名的文件名 URL。
返回值
类型:EnvDTE.ProjectItem
返回 ProjectItem 对象,该对象是新的“Web 引用”文件夹。
备注
如果 WebReferencesFolder 为 Nothing(一个 nullnull 引用(在 Visual Basic 中为 Nothing) 引用),则创建项目的“Web 引用”文件夹的 ProjectItem,并设置 WebReferencesFolder。
在创建了对 Web 服务的 Web 引用后,将向项目的 ProjectItems 集合添加新文件夹类型 ProjectItem。 这个新的 ProjectItem 在其 ProjectItems 属性中包含组成 Web 引用规范的各项。 下表描述了 Web 引用规范中所包含项的四种类型。
| Item | 用途 | 
|---|---|
| 映射文件 (Reference.map) | 该 XML 文件将 URL 映射到本地缓存文件位置。 它列出 Web 服务的发现文件和服务合同文件。 | 
| 服务合同文件 (.wsdl) | 这些 SOAP 文件指定 Web 服务的接口。 “Web 引用”文件夹中可能存在不止一个合同文件。 | 
| XML 架构定义文件 (.xsd) | 这些文件包含 Web 服务的 XML 架构定义。 “Web 引用”文件夹中可能存在不止一个架构文件。 | 
| 发现文件(.disco 或 .vsdisco) | 此 XML 文件包含指向描述 Web 服务的其他资源的链接。 | 
示例
[Visual Basic]
' Macro Editor
Imports VSLangProj
Sub AddWebReferenceExample()
   ' This example assumes that the first project in the solution is 
   ' either a Visual Basic or C# project.
   Dim aVSProject As VSProject = _
       CType(DTE.Solution.Projects.Item(1).Object, VSProject)
        
   ' The new project item is a folder.
   Dim newFolder As ProjectItem
   newFolder = aVSProject.AddWebReference( _
   "https://ServerName/Application/myServiceName.asmx")
   ' The new name of the folder appears in Solution Explorer.
   newFolder.Name = "NewName"
   ' The ProjectItems collection for the folder is not empty.
   MsgBox(newFolder.ProjectItems.Count.ToString())
End Sub
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。