WCF Windows Forms Sample

This sample demonstrates a service that implements a contract that defines a request and reply communication pattern. The sample consists of a client Windows Forms application (.exe) and a Windows Communication Foundation (WCF) service that is hosted by Internet Information Services (IIS).

To get samples and instructions for installing them

  • Do one or more of the following:

    • On the Help menu, click Samples.

      The Readme displays information about samples.

    • Visit the Visual Studio 2008 Samples Web site. The most recent versions of samples are available there.

    • Locate samples on the computer on which Visual Studio is installed. By default, samples and a Readme file are installed in drive:\Program Files\Microsoft Visual Studio 9.0\Samples\lcid. For Express editions of Visual Studio, all samples are located online.

For more information, see Visual Studio Samples.

Security noteSecurity Note:

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To run the sample

  1. In Solution Explorer, open the .sln file.

  2. Press F5.


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, which is a graphical representation of the data, is defined in the Windows Forms Designer. An intermediary named BindingSource is also created. The data source of the BindingSource is set to the data array that is 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 done by using calls to the BindingSource component. To accomplish data binding to the DataGridView, the data source 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 DataGridView.

See Also


Consuming ASMX and WCF Services Sample

Walkthrough: Creating and Accessing WCF Services