Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
En este ejemplo se muestra cómo enlazar a objetos devueltos por llamadas a métodos del servicio Web.
Ejemplo
En este ejemplo se utiliza MSDN/TechNet Publishing System (MTPS) Content Service para recuperar la lista de idiomas admitidos por un documento concreto.
Antes de llamar a un servicio Web, es preciso crear una referencia a él. Para crear una referencia web al servicio de MTPS mediante Microsoft Visual Studio, siga estos pasos:
Abra el proyecto en Visual Studio.
En el menú Proyecto, haga clic en Agregar referencia Web.
En el cuadro de diálogo, establezca la Dirección URL en http://services.msdn.microsoft.com/contentservices/contentservice.asmx?wsdl.
Haga clic en Ir y, a continuación, en Agregar referencia.
Luego, llame al método del servicio Web y establezca la propiedad DataContext del control o la ventana de que se trate en el objeto devuelto. El método GetContent del servicio MTPS toma una referencia al objeto getContentRequest. Por consiguiente, en el ejemplo siguiente se configura primero un objeto de solicitud:
' 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);
Una vez establecido DataContext, puede crear enlaces a las propiedades del objeto en que se ha establecido DataContext. En este ejemplo, DataContext se ha establecido en el objeto getContentResponse devuelto por el método GetContent. En el ejemplo siguiente, ItemsControl muestra los valores de locale de availableVersionsAndLocales de getContentResponse, y se enlaza a esta propiedad.
<ItemsControl Grid.Column="1" Grid.Row="2" Margin="0,3,0,0"
ItemsSource="{Binding Path=availableVersionsAndLocales}"
DisplayMemberPath="locale"/>
Para obtener información sobre la estructura de getContentResponse, consulte Content Service documentation.
Vea también
Tareas
Cómo: Hacer que los datos estén disponibles para el enlace en XAML