Home > DeveloperSection > Articles > Introduction to Web Service in ASP.NET

Introduction to Web Service in ASP.NET


.NET C#  ASP.Net  Web Services 
Ratings:
1 Comment(s)
 1401  View(s)
Rate this:

Introduction to Web Service in ASP.NET

Hi everyone in this article I’m explaining about How to make Web Service in ASP.NET.

Introduction:

In this post we will teach you about web service using the scenario when our application often require code to determine the number of days, such as how long the customer is associated with us, also to convert from a date of present days into days or years and so on.

In a normal application I need to write the business logic repeatedly for the same requirements so due to the requirements you can write a single web service for multiple application that allow an access method on any platform used, so let us start with the basic.

What is web service?

A "web service is the communication platform between two different or same platform applications that allows to use their web method."

What does different or same application and platform mean?

It means that I can create a web service in any language, such as Java or other languages and that the language web service can be used in a .Net based application and also a .Net web service or in another application to exchange the information.

What does web method mean?

The method in web services always start with [webMethod] attributes, it means that it is a web method that is accessible anywhere, the same as my web application.

 

Start make a web service:

Step 1: Open visual Studio >> File >> New Project >> ASP.NET Web Service Application >> Provide the Application Name >> Click OK

 

Step 2: the right click on solution explorer and click Add New item and you choose web service template.

 

Then open the Webservice.cs class and write the following method followed by [webMethod] attribute as in.

 

[WebMethod]

public int converttodaysweb(int day, int month, int year)

{

     DateTime dt = new DateTime(year, month, day);

     int datetodays = DateTime.Now.Subtract(dt).Days;

     return datetodays;

} 

 

Now run the application

Output:

 

Now in the above we see our method that we are created in the webservice.cs file, so click on that method and provide input values and click on the "invoke" link as in.

 

The output will be as follows


Where is Kamlakar Singh Photo?

By Abhishek Singh on   4 months ago
Where is Kamlakar Singh Profile Picture

Don't want to miss updates? Please click the below button!

Follow MindStick