Share via


VSProject2.AddWebReference 메서드

프로젝트에 웹 서비스에 대한 참조를 추가합니다. 프로젝트의 Web References 폴더에 새 웹 서비스 참조의 하위 폴더가 추가됩니다. 이 폴더에는 웹 서비스와 관련된 여러 프로젝트 항목이 포함됩니다. 이 메서드는 새 웹 서비스 폴더와 관련된 ProjectItem 개체를 반환합니다.

네임스페이스:  VSLangProj80
어셈블리:  VSLangProj80(VSLangProj80.dll)

구문

‘선언
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

매개 변수

  • bstrUrl
    형식: String

    필수입니다. 일반적으로 이 매개 변수는 .disco 또는 .vsdisco 확장명을 가진 파일 이름 URL입니다.

반환 값

형식: ProjectItem
새 Web Reference 폴더인 ProjectItem 개체를 반환합니다.

설명

WebReferencesFolder가 Nothing(nullNull 참조(Visual Basic의 경우 Nothing) 참조)이면 프로젝트에 대한 Web References 폴더의 ProjectItem이 만들어지고 WebReferencesFolder가 설정됩니다.

웹 서비스에 대한 웹 참조가 만들어지면 ProjectItem이라는 새 폴더 유형이 프로젝트의 ProjectItems 컬렉션에 추가됩니다. 이 새로운 ProjectItem에는 ProjectItems 속성에 웹 참조 사양을 구성하는 개별 항목이 포함되어 있습니다. 다음 표에는 웹 참조 사양에 포함된 네 가지 항목 형식에 대한 설명이 나와 있습니다.

항목

용도

맵 파일(Reference.map)

이 XML 파일은 URL을 로컬 캐시 파일의 위치로 매핑합니다. 웹 서비스의 검색 파일 및 서비스 계약 파일의 목록을 표시합니다.

서비스 계약 파일(.wsdl)

이 SOAP 파일에서는 웹 서비스의 인터페이스를 지정합니다. Web References 폴더에는 여러 개의 계약 파일이 있을 수 있습니다.

XML 스키마 정의 파일(.xsd)

이 파일에는 웹 서비스의 XML 스키마 정의가 있습니다. Web References 폴더에는 여러 개의 스키마 파일이 있을 수 있습니다.

검색 파일(.disco 또는 .vsdisco)

이 XML 파일에는 웹 서비스를 설명하는 다른 리소스에 대한 링크가 있습니다.

예제

이 예제에서는 Visual Basic 또는 Visual C# 프로젝트에 웹 서비스를 추가합니다. 이 샘플을 실행하기 전에 bstrUrl 매개 변수인 https://ServerName/Application/myServiceName.asmx를 실제 URL로 바꿉니다. 이 예제를 추가 기능으로 실행하려면 방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행을 참조하십시오.

[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 보안

참고 항목

참조

VSProject2 인터페이스

VSLangProj80 네임스페이스