Data Binding in a Windows Forms Client
This sample demonstrates how to bind to data returned by a Windows Communication Foundation (WCF) service in a Windows Forms application.
The setup procedure and build instructions for this sample are located at the end of this article.
This sample demonstrates a service that implements a contract that defines a request-reply communication pattern. The sample consists of a client Windows Forms application (.exe) and a WCF service hosted by Internet Information Services (IIS).
The contract is defined by the
IWeatherService interface, which exposes an operation named
GetWeatherData. This operation accepts an array of cities and returns an array of
WeatherData objects that represent the high and low forecasted temperature for a city.
The data binding occurs on the client in the Windows Forms application. A
DataGridView is defined in the Windows Forms designer, which is a graphical representation of the data. An intermediary named
BindingSource is also created. The data source of
BindingSource is set to the data array returned by the service. The purpose of the
BindingSource is to provide a layer of indirection between the data and the data view. All interaction with the data, such as navigating, sorting, filtering, and updating, is accomplished with calls to the
BindingSource component. To accomplish data binding to the
datasource of the
DataGridView is then set to the
BindingSource object. All of the data returned from the WCF service is then displayed graphically to the user. Every time the user clicks the button, the returned data is automatically updated in the data-bound
To set up, build, and run the sample
Ensure that you have performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.
To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.
To run the sample in a single- or cross-machine configuration, follow the instructions in Running the Windows Communication Foundation Samples.
The samples may already be installed on your machine. Check for the following (default) directory before continuing.
If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.