In this tutorial we will show you how to connect your application to a web service using the Data Source Configuration Wizard. This will allow you to run queries from your application through Microsoft’s Live Search web service. Any data returned by the service will be displayed on your Windows Form that you will create.

First, you will need to obtain a free AppID from http://www.bing.com/developer/.

Copy and paste this link into your browser and then locate the “Get an AppID” on the bing.com page and follow the steps. To begin, you will need to create a new project. File > New > Project > Windows Forms Application and name it WebServTut > OK. Notice that the project is created in the Solution Explorer.

Next, we will need to connect to the service.

We can do this by running the Data Source Configuration Wizard. From the data menu simply click “Show Data Source”. Then from the “Data Source” window, select “Add New Data Source”. Then you’re prompted with a window.

  • Choose > Service then click next and type http://soap.search.msn.com/webservices.asmx?wsdl in the URL box and click Go.
  • Once the Web service is found, change the namespace to “LiveSearchService” > click OK.

***These configurations are only for demonstration purposes only. Different web services expose different functionality.

Here is the typical process for consuming data from a service:

  • First create an instance of the service,
  • then call methods exposed by the service.
  • Then drag the items from the Data Source window.
  • From there they should contain a BindingSource component.
  • Simply set the properties to the data returned by the service.
  • Now we want to create a DataGridView to display the data returned by the service.

    Now within the Data Sources window, expand the SearchResponse node and then expand the Response node, then drag over the results node onto the form. Notice how DataGridView, BindingSource, and BindingNavigator are added to the form.

    Now select the resultsDataGridView that you added to the form and locate the properties window.

    From there select Columns and click the ellipses(..) to open the Edit Columns Dialog Box. Select the URL column and set the ColumnType property to DataGridViewLinkColumn and AutoSizeMode property to AllCells. Now let’s remove all columns except for Title, Description, URL and click OK.

    Now we need to add controls for entering search criteria and running the search query.

    To add a text box and button to the form simply right click the grayed disk icon on the form tool strip and select insert > Textbox. Locate the properties window and set the name property to tbxSearchCriteria and set the text to “Search”.

    Next add a button the same way and name it btnSearch and set the DisplayStyle property to text and the Text property to “Search”.

    Now we need to create an event handler for the CellContentClick event.

    In order to create an event handler to open the web site when clicked in the grid we first need to select the resultsdataGridview on the form and click the Events button in the properties window. Double-click the CellContentClick event to create and navigate to the handler stub and add this code below:

    This code checks which column was clicked and to navigate to the web page if the URL column is checked.

    Lastly, we need to add code in order to access the Live Search Service and run a search query.

    We can access this service by instantiating an instance of the service in your application and calling the methods exposed by the service. Open Form1 in the code editor and add the following method to it:

    ***Make sure to replace the searchrequest.AppID = ‘AppID” with the AppID value that you obtained from the live search service.

    Open Form1 and Double-click the search button and add this code to create an event handler to run a search when the search button is clicked:

    Save and run the application. The Grid displays first 10 search results.