Nasıl Yapılır: Web Hizmetine Bağlama
This example shows how to bind to objects returned by Web service method calls.
Örnek
Bu örnek kullanır msdn/TechNet yayımlama sistemi (mtps) içerik hizmeti belirtilen belge tarafından desteklenen diller listesini almak için.
Before you call a Web service, you need to create a reference to it. To create a Web reference to the MTPS service using Microsoft Visual Studio, follow the following steps:
Open your project in Visual Studio.
From the Project menu, click Add Web Reference.
İletişim kutusunda ayarlanan url için http://services.msdn.microsoft.com/contentservices/contentservice.asmx?wsdl.
Press Go and then Add Reference.
Next, you call the Web service method and set the DataContext of the appropriate control or window to the returned object. The GetContent method of the MTPS service takes a reference to the getContentRequest object. Therefore, the following example first sets up a request object:
' 1. Include the web service namespace
Imports 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
Dim request As New getContentRequest()
request.contentIdentifier = "abhtw0f1"
' 3. Create the proxy
Dim proxy As New ContentService()
' 4. Call the web service method and set the DataContext of the Window
' (GetContent returns an object of type getContentResponse)
Me.DataContext = proxy.GetContent(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);
After the DataContext has been set, you can create bindings to the properties of the object that the DataContext has been set to. In this example, the DataContext is set to the getContentResponse object returned by the GetContent method. In the following example, the ItemsControl binds to and displays the locale values of availableVersionsAndLocales of getContentResponse.
<ItemsControl Grid.Column="1" Grid.Row="2" Margin="0,3,0,0"
ItemsSource="{Binding Path=availableVersionsAndLocales}"
DisplayMemberPath="locale"/>
Yapısı hakkında bilgi getContentResponsebakın içerik hizmeti belgelerine.
Ayrıca bkz.
Görevler
Nasıl Yapılır: XAML'de Bağlama için Veriyi Kullanılabilir Yapma