Share via


VSProject.AddWebReference Method

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.

Namespace:  VSLangProj
Assembly:  VSLangProj (in VSLangProj.dll)

Syntax

'Declaration
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

Parameters

  • bstrUrl
    Type: String

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

Return Value

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

Remarks

If the WebReferencesFolder is Nothing (a nulla null reference (Nothing in Visual Basic) 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.

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( _
   "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 Security

See Also

Reference

VSProject Interface

VSLangProj Namespace