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
- Open VS
- Create new ASP.net Web Service Application
- Open Server Explorer
- Add connection to “pubs” database from the Server Explorer
- Add a DataSet to the Solution
- From the Server Explorer Window, drop the authors table of the Server explorer onto the DataSet Designer
- Build the Solution.
- Open Service1.asmx file in the designer
- Drop the DataSet1, authorsTableAdapter components from the toolbox onto the Service1’s designer
- Build the App
- Add the following code to the Service1 class
- [WebMethod]
- public DataSet1 getDS()
- {
- InitializeComponent();
- this.authorsTableAdapter1.Fill(dataSet11.authors);
- return dataSet11;
- }
- 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.
- Copy the Web service to the inetpub\wwwroot folder
- Type ‘inetmgr’ in the run window. Internet Information Services Window appears
- Browse to the folder containing the asmx file of the web service (Internet Information Services -> Computer Name -> Web Sites -> Default Web Site -> WebService1 -> WebService1)
- Right click on the WebService1 node and click on properties. “WebService1 Properties” dialog appear
- Click the “Create” button to create the application. Click “Apply” and then “ok” buttons
- Now WebService1 Application is created on the server.
- Exit iis
- Restart iis using the following commands
- aspnet_regiis –i –enable
- iisreset
- from run command, type inetmgr
Part III. Accessing from the Client
This is described in my previous blog post
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
- Drop “Service1” from the toolbox onto the form
- Drop “DataSet” under the Data area from the toolbox on to the form. Select TypedDataSet with name “WindowsApplicationName.WebServerName.DataSet1”
- 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.