Hi everyone in this article I’m explaining about How to make
Web Service in ASP.NET.
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.
public int converttodaysweb(int day, int month, int year)
DateTime dt = new DateTime(year, month, day);
int datetodays = DateTime.Now.Subtract(dt).Days;
Now run the application
The output will be as follows :