Aracılığıyla paylaş


VSProject2.AddWebReference Yöntem

Bir Web servisine başvuru projeye ekler.Yeni bir Web hizmeti başvurusu alt projenin Web başvurular klasörüne eklenir.Bu yeni klasör Web hizmeti ile ilgili diğer birçok proje öğeleri içerir.Bu yöntem döndürür ProjectItem yeni Web hizmeti klasörle ilişkilendirilmiş nesne.

Ad alanı:  VSLangProj80
Derleme:  VSLangProj80 (VSLangProj80.dll içinde)

Sözdizimi

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

Parametreler

  • bstrUrl
    Tür: String

    Gerekli.Genellikle, bu bir dosya adı uzantısına sahip bir .disco veya .vsdisco URL'sidir.

Dönüş Değeri

Tür: ProjectItem
Döndüren bir ProjectItem yeni klasörün Web başvuru nesnesi.

Notlar

Yoksa WebReferencesFolder olan Nothing (bir nullnull başvuru (Visual Basic'te Nothing) başvuru), daha sonra bir ProjectItem Web başvuruları için proje için bir klasör oluşturulur ve WebReferencesFolder ayarlanır.

Bir Web hizmeti için Web başvurusu oluşturulduğunda, yeni bir klasör türü ProjectItem, projenin eklenen ProjectItems koleksiyonu.Bu yeni ProjectItem de içeren kendi ProjectItems özelliği, bir Web başvurusu belirtim, tek tek öğeleri.Dört tür bir Web başvurusu belirtiminin içerdiği öğeler aşağıdaki tabloda açıklanmıştır.

Madde

Purpose

Eşleme dosyası (Reference.Map'i)

Bu XML dosyası URL'lerini yerel önbelleğe alınmış dosya konumuyla eşleştirir.Onu bulma dosyasının Web hizmetinin Hizmet sözleşmesi dosyaları listeler.

Servis Sözleşmesi dosyaları (.wsdl)

Bu SOAP dosyaları Web hizmeti arabirimi belirtin.Web başvurusu klasöründe birden fazla sözleşme dosyası olabilir.

XML şema tanımı dosyaları (.xsd)

Bu dosyalar Web hizmeti XML şema tanımlarını içerir.Web başvurusu klasöründe birden çok şema dosyası olabilir.

Keşif dosyası (.disco veya .vsdisco)

Bu XML dosyası, Web hizmetini tanımlayan diğer kaynaklara bağlantılar içerir.

Örnekler

Bu örnek, bir web hizmetine ekler bir Visual Basic veya Visual C# proje.Bu örnek çalıştırmadan önce yerine bstrUrl parametre: https://ServerName/Application/myServiceName.asmx, gerçek bir URL ile.Bir eklenti bu örneği çalıştırmak için bkz: Nasıl yapılır: Otomasyon Nesne Modeli Kod Örnekleri Derleme ve Çalıştırma.

[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());
}

.NET Framework Güvenliği

Ayrıca bkz.

Başvuru

VSProject2 Arabirim

VSLangProj80 Ad Alanı