VSProject.AddWebReference(String) 方法

定义

向项目添加对 Web 服务的引用。 新的 Web 服务引用子文件夹将添加到项目的 "Web 引用" 文件夹中。 此新文件夹包含与 Web 服务相关的其他几个项目项。 方法返回 ProjectItem 与新的 Web 服务文件夹关联的对象。

public:
 EnvDTE::ProjectItem ^ AddWebReference(System::String ^ bstrUrl);
public:
 EnvDTE::ProjectItem ^ AddWebReference(Platform::String ^ bstrUrl);
EnvDTE::ProjectItem AddWebReference(std::wstring const & bstrUrl);
[System.Runtime.InteropServices.DispId(7)]
public EnvDTE.ProjectItem AddWebReference (string bstrUrl);
[<System.Runtime.InteropServices.DispId(7)>]
abstract member AddWebReference : string -> EnvDTE.ProjectItem
Public Function AddWebReference (bstrUrl As String) As ProjectItem

参数

bstrUrl
String

必需。 通常,这是扩展名为 .disco 或 .vsdisco 的文件名 URL。

返回

ProjectItem

返回一个 ProjectItem 对象,该对象是新的 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( _  
   "http://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  

注解

如果 WebReferencesFolder Nothing (null 引用) ,则会 ProjectItem 创建项目的 "Web 引用" 文件夹的,并 WebReferencesFolder 设置。

创建 Web 服务的 Web 引用时,会将新的文件夹类型 ProjectItem 添加到项目的 ProjectItems 集合中。 这一新 ProjectItem 包含在其 ProjectItems 属性中组成 Web 引用规范的各个项。 下表描述了 Web 引用规范中包含的四种类型的项。

用途
映射文件 (引用 .map) 此 XML 文件将 Url 映射到本地缓存的文件位置。 它列出了 Web 服务的发现文件和服务协定文件。
服务协定文件 ( .wsdl) 这些 SOAP 文件指定 Web 服务的接口。 "Web 引用" 文件夹中可能有多个协定文件。
XML 架构定义文件 ( .xsd) 这些文件包含 Web 服务的 XML 架构定义。 "Web 引用" 文件夹中可能有多个架构文件。
发现文件 ( .disco 或 .vsdisco) 此 XML 文件包含指向描述 Web 服务的其他资源的链接。

适用于