Web service in ASP.NET

A. How to create web-service in ASP.NET?
 
Step 1: Go to=>File=>New=>WebSite
 
w.png
 
Step 2: Select Asp.New Web service 
 
w1.jpg
 
Step 3: Write Method in your web service class file.
 
My method name is: MyServiceMethod
 
w2.jpg
 
Step 4: Then Run This Application and watch this window in your browser. And also look at the method that has been created by me. Here you can test whether your method works properly or not.
 
w3.jpg
 
B. Publish This service on your local IIS server.
 
Step 1: Right click on your application=>Publish Web site
 
w4.png
 
Step 2: Checked =>Use Fixed Naming and single page assemblies and browse target location.
 
w5.PNG
 
Step 3: Select=>Local IIS=>Default Website=>Create New Web Application by clicking on the small icon located at the above of this Screen shot.=>write name of your application.and click on Open button.
 
=>You can access this web service using=>  http://localhost/mytestwebservice URL
 
w6.jpg
 
Step 4=> After that click OK button.
 
w7.PNG
 
Step 5=> After that you can access the the web service using this URL http://localhost/mytestwebservice/Service.asmx
 
C. How to consume Web service in Web Application?
 
Consuming Web service :
 
=>Using WSDL generated Proxy class.=>How to generate proxy class?
 
Step 1=>Open Command Prompt.From=>Start=>
 
w8.png
 
 
Step 2=> Write this command on Command Prompt.
  Open=>Command prompt=>right click=>paste below written command
w9.png
Formate of command=>wsdl /l:CS /n:namespace /o:DriveName:\classname.cs Service URL
 
wsdl /l:CS /n:myserviceclassnameSpace /o:d:\myserviceclassname.cs http://localhost/mytestwebservice/Service.asmx
 
w10.PNG
After that Press enter.
Using this command generate the proxy class file of the web service.you can use this class in in your web and window application.

Step 3=>Add myserviceclassname.cs file in your application and consume service in your application.

w11.PNG

Step 4=>Call method of service class like this:

w12.PNG

Step 5=> Out put is=>

w13.PNG