다음을 통해 공유


방법: 웹 서비스 바인딩

업데이트: 2007년 11월

이 예제에서는 웹 서비스 메서드 호출에 의해 반환된 개체에 바인딩하는 방법을 보여 줍니다.

예제

이 예제에서는 MSDN/TechNet Publishing System (MTPS) Content Service를 사용하여 지정한 문서에서 지원되는 언어 목록을 검색합니다.

웹 서비스를 호출하기 전에 해당 웹 서비스에 대한 참조를 만들어야 합니다. Microsoft Visual Studio를 사용하여 MTPS 서비스에 대한 웹 참조를 만들려면 다음 단계를 수행하십시오.

  1. Visual Studio에서 프로젝트를 엽니다.

  2. 프로젝트 메뉴에서 웹 참조 추가를 클릭합니다.

  3. 대화 상자에서 URL을 http://services.msdn.microsoft.com/contentservices/contentservice.asmx?wsdl로 설정합니다.

  4. 이동을 누른 다음 참조 추가를 누릅니다.

그런 다음 웹 서비스 메서드를 호출하여 적절한 컨트롤이나 창의 DataContext를 반환된 개체로 설정합니다. MTPS 서비스의 GetContent 메서드는 getContentRequest 개체에 대한 참조를 사용합니다. 그러므로 다음 예제에서는 먼저 Request 개체를 설정합니다.

// 1. Include the web service namespace
using BindtoContentService.com.microsoft.msdn.services;


...


// 2. Set up the request object
// To use the MSTP web service, we need to configure and send a request
// In this example, we create a simple request that has the ID of the XmlReader.Read method page
getContentRequest request = new getContentRequest();
request.contentIdentifier = "abhtw0f1";

// 3. Create the proxy
ContentService proxy = new ContentService();

// 4. Call the web service method and set the DataContext of the Window
// (GetContent returns an object of type getContentResponse)
this.DataContext = proxy.GetContent(request);

DataContext가 설정된 다음 DataContext가 설정되었던 개체의 속성에 대한 바인딩을 만들 수 있습니다. 이 예제에서는 DataContextGetContent 메서드에서 반환된 getContentResponse 개체로 설정됩니다. 다음 예제에서 ItemsControlgetContentResponse에 대한 availableVersionsAndLocaleslocale 값에 바인딩되고 이 값을 표시합니다.

<ItemsControl Grid.Column="1" Grid.Row="2" Margin="0,3,0,0"
              ItemsSource="{Binding Path=availableVersionsAndLocales}"
              DisplayMemberPath="locale"/>

getContentResponse의 구조체에 대한 자세한 내용은 Content Service 설명서를 참조하십시오. 전체 샘플을 보려면 웹 서비스 바인딩을 참조하십시오.

참고 항목

작업

방법: XAML의 바인딩에 사용할 수 있는 데이터 만들기

개념

데이터 바인딩 개요

바인딩 소스 개요