articles

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

Introduction to Web Service in ASP.NET

Anonymous User4143 01-Jun-2015

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

Introduction to Web Service in ASP.NET

 

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

Introduction to Web Service in ASP.NET

 

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 :

Introduction to Web Service in ASP.NET

 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.

Introduction to Web Service in ASP.NET

 

The output will be as follows :

Introduction to Web Service in ASP.NET


Updated 07-Sep-2019
I am a content writter !

Leave Comment

Comments

Liked By