Monday, 27 May 2013

Design one web service which will take department number and provide the details of employee belongs to that department.

First create one table in your database(Employee.mdf) and give name Employee in project directory and store some data for our testing purpose.
 
Then create new web application in asp.net

Open visual studio ---> Select File ---> New ---> Web Site ---> select ASP.NET Web Service
--- > choose Location: HTTP ------>choose Language: Visual C# --> Browse --> Select LocalIIS ---> Create New Web Application (named "WebServiceGridView") under the "Default Web Site" ---> Open ---> OK
After this process you can check  a directory  named "WebServiceGridView" in  C:\Inetpub\wwwroot\    created.
Then create new web service application in asp.net

In Opened visual studio ---> Go Website (Menu) --->Add New Item ---> Web Service ---> Rename WebService.asmx to Service.asmx
Now open your Service.cs file in web service website under the App_Code directory to write the code to get the employee details belongs to taken department number from database.

Service.cs
By using this webservice we can get the employee details belongs to that department.
 For that first create one new web application

In Opened visual studio ---> Go Website (Menu) ---> Add New Item ---> Web Form ---> Rename Default.aspx to  GridResult.aspx.

After creation of new website right click on solution explorer and choose “Add web reference”.
After select Add Web reference option one window will open, then you enter your locally deployed web service link i.e, http://localhost/WebServiceGridView/Service.asmx 
and click Go button.
Now click on Add Reference button (Right Side) web service will add successfully.
Then check your solution explorer like this...
 
 Now open your GridResult.aspx page and design like this................. 

GridResult.aspx

Code View:
GridResult.cs: 
Now run your application and check output:
Here Entered Department no is 10, then show this..... 
 
 Suppose, Entered department number is not exist, then show appropriate message..
 

No comments:

Post a Comment