Dela via


How to: Bind Data Returned by a Service

You can bind data returned by a Windows Communication Foundation (WCF) service to a control just as you can bind any other data source to a control. When you add a reference to a WCF service, if the service contains composite types that return data, they are automatically added to the Data Sources window.

To bind a control to single data field returned by a WCF service

  1. On the Data menu, click Show Data Sources. The Data Sources window will appear.

  2. In the Data Sources window, expand the node for your service reference. Any composite types returned by the service will be displayed.

  3. Expand a node for a type. The data fields for that type will be displayed.

  4. Select a field and click the drop-down arrow to display a list of controls that are available for the data type.

  5. Click the type of control that you want to bind to.

  6. Drag the field onto a form. The control will be added to the form together with a BindingSource component and a BindingNavigator component.

  7. Repeat steps 4 though 6 for any other fields that you want to bind.

To bind a control to composite type returned by a WCF service

  1. On the Data menu, select Show Data Sources. The Data Sources window will appear.

  2. In the Data Sources window, expand the node for your service reference. Any composite types returned by the service will be displayed.

  3. Select a node for a type and click the drop-down arrow to display a list of available options.

  4. Click either DataGridView to display the data in a grid or Details to display the data in individual controls.

  5. Drag the node onto the form. The controls will be added to the form together with a BindingSource component and a BindingNavigator component.

See Also

Tasks

How to: Add a Reference to a Web Service

Consuming ASMX and WCF Services Sample

How to: Bind Data to the Windows Forms DataGridView Control Using the Designer

Reference

Add Service Reference Dialog Box

Data Sources Window

Other Resources

Windows Communication Foundation Services and ADO.NET Data Services