WebService that returns a Dataset

In this post, I describe how to create a WebService that returns a DataSet, deploying the web service, accessing the data from the webservice, and using it with winforms controls

 

Part1 : WebService Creation

 

  1. Open VS
  2. Create new ASP.net Web Service Application
  3. Open Server Explorer
  4. Add connection to “pubs” database from the Server Explorer
  5. Add a DataSet to the Solution
  6. From the Server Explorer Window, drop the authors table of the Server explorer onto the DataSet Designer
  7. Build the Solution.
  8.  Open Service1.asmx file in the designer
  9. Drop the DataSet1, authorsTableAdapter components from the toolbox onto the Service1’s designer
  10. Build the App
  11. Add the following code to the Service1 class
    1.         [WebMethod]
    2.        public DataSet1 getDS()
    3.         {
    4.             InitializeComponent();
    5.             this.authorsTableAdapter1.Fill(dataSet11.authors);
    6.             return dataSet11;
    7.         }
  12. Build the Application.

 

Part II. WebService Deployment on the server

The web service can be deployed using iis (Internet Information Server).

The following steps have to be followed.

  1. Copy the Web service to the inetpub\wwwroot folder
  2. Type ‘inetmgr’ in the run window. Internet Information Services Window appears
  3. Browse to the folder containing the asmx file of the web service (Internet Information Services -> Computer Name -> Web Sites -> Default Web Site -> WebService1 -> WebService1)
  4. Right click on the WebService1 node and click on properties. “WebService1 Properties” dialog appear
  5. Click the “Create” button to create the application. Click “Apply” and then “ok” buttons
  6. Now WebService1 Application is created on the server.
  7. Exit iis
  8. Restart iis using the following commands
    1. aspnet_regiis –i –enable
    2. iisreset
  9. from run command, type inetmgr

 

Part III. Accessing from the Client

 

This is described in my previous blog post

https://blogs.msdn.com/nagasatish/archive/2007/10/17/adding-a-web-reference-to-a-vs-2008-windows-forms-project.aspx

 

Part IV Binding to Winforms Controls

After Doing the steps in step III, you will be able to bind winforms controls to the dataset returned from the web service.

 

In the project from step3,after building the project

  1. Drop “Service1” from the toolbox onto the form
  2. Drop “DataSet” under the Data area from the toolbox on to the form. Select TypedDataSet with name “WindowsApplicationName.WebServerName.DataSet1”
  3. Drop a textbox onto the form. Bind to the author’s table au_id field.

In this way you can access a web service and bind to windows forms controls.