Compartilhar via


VSProject.AddWebReference(String) Method

Definition

Adds a reference to a Web Service to the project. A new Web Service reference subfolder is added to the Web References folder of the project. This new folder contains several other project items related to the Web Service. The method returns the ProjectItem object associated with the new Web Service folder.

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

Parameters

bstrUrl
String

Required. Typically, this is a file name URL with a .disco or .vsdisco extension.

Returns

Returns a ProjectItem object that is the new Web Reference folder.

Attributes

Examples

[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  

Remarks

If the WebReferencesFolder is Nothing (a null reference), then a ProjectItem for the Web References folder for the project is created and the WebReferencesFolder is set.

When a Web reference to a Web Service is created, a new folder type, ProjectItem, is added to the project's ProjectItems collection. This new ProjectItem contains, in its ProjectItems property, the individual items that make up a Web reference specification. The four types of items included in a Web reference specification are described in the following table.

Item Purpose
Map file (Reference.map) This XML file maps URLs to the local cached file location. It lists the discovery file and the service contract files for the Web Service.
Service Contract files (.wsdl) These SOAP files specify the interface of the Web Service. There may be more than one contract file in the Web Reference folder.
XML Schema Definition files (.xsd) These files contain XML schema definitions for the Web Service. There may be more than one schema file in the Web Reference folder.
Discovery file (.disco or .vsdisco) This XML file contains links to other resources that describe the Web Service.

Applies to