Microsoft Visual C# 2005 Unleashed
One of the powerful new features of Windows Forms is the consolidated Data Sources panel. This panel shows you a list of available data sources that can then be dragged onto any form in the application. For example, if you have created a DataSet, that DataSet will appear in the Data Sources panel and you can then drag it onto the surface of a form, creating either a grid view or a details view. One of the types of data sources is a web service. This section of the chapter walks you though building a web service that returns data through a web method. The schema of this data is then interpreted as a data source by the Windows Forms client, allowing that client to bind directly to data returned by a web service. The following steps will walk you through the process of using a web service as a data source. While reading these steps, it is important to keep in mind a very important distinction: The web service itself is not the data sourceonly the data types returned from that service are considered data sources. In other words, a web service data source will not automatically invoke methods; it only obtains the schema from the web service and uses that schema to prepare the data source. The following steps will take you through the process of binding to a web service:
Figure 33.6. A DataGridView populated by a web service.
Unlike other kinds of data sources that can be automatically updated by the controls to which they are bound, you will have to write your own code to invoke the appropriate update methods on the web service because there is no way for the data source to know which methods on which web service to invoke in response to data change events. However, even with that minor bit of required coding, the ability to bind controls to data retrieved directly from web services is a powerful tool, especially for smart client applications and SOA infrastructures. |