Condividi tramite


Metodo VSProject2.AddWebReference (String)

Aggiunge un riferimento ad un servizio Web nel progetto.Viene aggiunta una nuova sottocartella di riferimento del servizio Web alla cartella dei riferimenti Web del progetto.Questa nuova cartella contiene numerosi altri elementi del progetto relativi al servizio Web.Il metodo restituisce l'oggetto ProjectItem associato alla nuova cartella del servizio Web.

Spazio dei nomi:  VSLangProj80
Assembly:  VSLangProj80 (in VSLangProj80.dll)

Sintassi

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

Parametri

  • bstrUrl
    Tipo: System.String
    Obbligatorio.Normalmente si tratta dell'URL di un nome file con estensione .disco o .vsdisco.

Valore restituito

Tipo: EnvDTE.ProjectItem
Restituisce un oggetto ProjectItem che è la nuova cartella dei riferimenti Web.

Note

Se la proprietà WebReferencesFolder è Nothing, ovvero un riferimento nullriferimento null (Nothing in Visual Basic), viene creato un elemento ProjectItem per la cartella dei riferimenti Web del progetto e viene impostata la proprietà WebReferencesFolder.

Quando viene creato un riferimento Web per un servizio Web, viene aggiunto un nuovo tipo di cartella, ProjectItem, alla raccolta ProjectItems del progetto.Questo nuovo ProjectItem contiene, nella sua proprietà ProjectItems, i singoli elementi che costituiscono una specifica del riferimento Web.I quattro tipi di elementi compresi nella specifica di un riferimento Web sono descritti nella tabella seguente.

Elemento

Scopo

File MAP (Reference.map)

Questo file XML effettua il mapping degli URL alla posizione locale del file memorizzato nella cache.Elenca il file di individuazione e i file del contratto di servizio per il servizio Web.

File del contratto di servizio (WSDL)

Questi file SOAP specificano l'interfaccia del servizio Web.Nella cartella dei riferimenti Web può esistere più di un file di contratto.

File di definizione XML Schema (XSD)

Questi file contengono le definizioni XML Schema per il servizio Web.Nella cartella dei riferimenti Web può esistere più di un file di schema.

File di individuazione (DISCO o VSDISCO)

Questo file XML contiene i collegamenti ad altre risorse che descrivono il servizio Web.

Esempi

Nell'esempio riportato di seguito viene aggiunto un servizio Web a un progetto di Visual Basic o Visual C#.Prima di eseguire l'esempio, sostituire il parametro bstrUrl: https://ServerName/Application/myServiceName.asmx con un URL reale.Per eseguire questo esempio come componente aggiuntivo, vedere Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione.

[Visual Basic]

' Add-in code.
Imports VSLangProj
Imports VSLangProj80
Public Sub OnConnection(ByVal application As Object,_
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    applicationObject = CType(application, DTE2)
    addInInstance = CType(addInInst, AddIn)
    AddWebReferenceExample(applicationObject)
End Sub
Sub AddWebReferenceExample(ByVal dte As DTE2)
    ' This example assumes that the first project in the solution is 
    ' a Visual Basic or C# project.
    Dim aVSProject As VSProject2 = _
    CType(applicationObject.Solution.Projects.Item(1).Object, _
    VSProject2)
    ' The new project item is a folder.
    Dim newFolder As ProjectItem
    ' Replace the sample URL with an actual URL.
    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

[C#]

using System.Windows.Forms;
using VSLangProj;
using VSLangProj2;
using VSLangProj80;

public void OnConnection(object application, ext_ConnectMode
 connectMode, object addInInst, ref Array custom)
{
    applicationObject = (DTE2)application;
    addInInstance = (AddIn)addInInst;
    AddWebReferenceExample((DTE2)applicationObject);
}

public void AddWebReferenceExample(DTE2 dte)
{
    // This example assumes that the first project in the solution is 
    // a Visual Basic or C# project.
    VSProject2 aVSProject =
 ((VSProject2)( applicationObject.Solution.Projects.Item(1).Object));
    // The new project item is a folder.
    ProjectItem newFolder = null;
    // Replace the sample URL with an actual URL.
    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.
    MessageBox.Show("Number of items in the Web Reference folder: \n"
 + newFolder.ProjectItems.Count.ToString());
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

VSProject2 Interfaccia

Overload AddWebReference

Spazio dei nomi VSLangProj80