Background
In this article, we will learn about web service using the scenario when Our applications often require code to determine the number of days, such as how long the customer is associated with us, also to convert from the 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 applications that allow an access method on any platform used, so let us start with the basics.
Per-requirement to understand this application
If you are a beginner and you need to understand what a web service is then you can read the article of the author Vidya Vrat Agarwal sir; the article is .NET Web Services.
I hope you read it if you are unfamiliar with web services.
What is a web service?
A "web service is the communication platform between two different or same platform applications that allows using their web method."
In the preceding definition, you observed that I used the two main points in the definition of web service; they are different or same platform application and the second is web method.
So let us learn some basics about it.
What does different or the 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 information.
What does the web method mean?
The method in web services always starts with [webMethod] attributes, which means that it is a web method that is accessible anywhere, the same as my web application.
To understand more clearly let us represent all the above-given definitions explanation in the following diagram.

In the above diagram, I have shown how the Asp.net Web Service is used in different types of applications. I am trying to explain 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 as well as Java or other applications and you can also use .Net based web application in Java applications means web Services don't have any platform restrictions.
I hope you understand the basics of a web service.
So let us start to create the web service.
Note. If you closely observe that, there is no separate web service template in .Framework 2010 as you see in 2008 while adding a project or website might be because of WCF.
So let us start using a different way to add a web service using a template.
- "Start" , "All Programs" , "Microsoft Visual Studio 2010".
- "File" , "New Project" , "C#" , "Empty Web Application" (to avoid adding a master page).
- Provide the website a name such as "agetodays" or another as you wish and specify the location.
- Then right-click on Solution Explorer "Add New Item" and you see the web service templates.

Select Web Service Template and click on the add button. Then after that, the Solution Explorer looks as follows.

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;
}
In the code above I have declared one integer method named converttodaysweb with the three parameters day, month, and year for accepting day, month, and year from the user.
Then after that, I created an object of date time and assigned those variables that I got from the users. I declared another variable in the method that is age today to store the number of days remaining from the user's input date to the current date and finally, I returned that variable.
The webservice.cs file will then look as in the following.
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
///<summary>
/// Summary description for UtilityWebService
///</summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService: System.Web.Services.WebService
{
public WebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[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 that looks as follows.

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

The output will be as follows.

In the screen above you see that the output is 8671, which is the days from the input date.
Note. For detailed code please download the zip file attached above.
Summary
From all the examples above we see how to convert a date into days. In my next article we will learn how to implement this web service in a web application so click here to learn Consuming Web Service In an ASP.Net Web Application. I hope this article is useful for all students and beginners. If you have any suggestions related to this article then please contact me.

Ganesh MPosted Jan 8, 2020, 7:11 AM
I cannot find the zip file here
Ashwin ChauhanPosted Nov 28, 2018, 10:28 PM
No i am send string data in postman but getting that error
Ashwin ChauhanPosted Nov 9, 2018, 11:23 PM
System.InvalidOperationException: Request format is invalid: multipart/form-data; boundary=----WebKitFormBoundary79Ky1A1Kfyyy7qUi. at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
Rajesh DintakurthiPosted Aug 10, 2018, 12:49 AM
Its very simply and understandable for all C# corner users
Hadshana KamalanathanPosted Jul 22, 2018, 1:04 AM
Good post..
Syed AtherPosted Oct 2, 2017, 12:36 AM
Very simple and understandable explanation for me as i am beginner Thank you sir
Amit SainiPosted May 6, 2017, 9:23 AM
Great sir ?? Very very helpful ????????????
Suresh BaiPosted Apr 19, 2017, 6:55 AM
Nice Article and good for beginner ...
Manish PandeyPosted Mar 17, 2017, 11:47 PM
As I m beginner in web services.. it is very helpful..Thank you sir.
Uday Bhan SinghPosted Feb 14, 2017, 2:23 AM
Simple easy to understand
DeepanPosted Nov 21, 2016, 3:45 PM
Simple easy to understand
Vithal WadjePosted Jan 14, 2016, 9:42 AM
thanks..
Yatendra SharmaPosted Jan 14, 2016, 5:14 AM
nicely explained
Vithal WadjePosted Jan 13, 2016, 9:42 AM
Thanks
Mohammed IbrahimPosted Jan 13, 2016, 8:17 AM
nice
Vithal WadjePosted Jan 11, 2016, 10:39 AM
Yes , refer my article list
Ehsan SajjadPosted Jan 11, 2016, 10:24 AM
Have you wrote any post on WCF services ?
Vithal WadjePosted Dec 30, 2015, 9:21 AM
Thanks
Vipul PatelPosted Dec 30, 2015, 9:06 AM
nice one...
Vithal WadjePosted Dec 4, 2015, 9:15 AM
refer my other article
varun chinnaPosted Dec 4, 2015, 7:14 AM
Nice One.....Can You Please Explain me How to Consume A Webservice in Windows mobile Application...Please
Vithal WadjePosted Nov 29, 2015, 10:35 PM
Thanks sir
Santhakumar MunuswamyPosted Nov 28, 2015, 1:41 AM
Good One
Vithal WadjePosted Nov 23, 2015, 9:54 AM
Thanks Harshad Pansuriya sir
Vithal WadjePosted Nov 23, 2015, 9:54 AM
Thanks Humayun Kabir Mamun sir
Vithal WadjePosted Nov 23, 2015, 9:53 AM
Thanks Rajeesh Menoth sir
Vithal WadjePosted Nov 23, 2015, 9:52 AM
Thanks Mukesh Kumar sir
Vithal WadjePosted Nov 23, 2015, 9:52 AM
Thanks kalu singh rao sir
Harshad PansuriyaPosted Nov 23, 2015, 2:54 AM
Nice
Humayun Kabir MamunPosted Nov 23, 2015, 12:28 AM
Nice...
Rajeesh MenothPosted Nov 22, 2015, 11:53 PM
Nice One Vithal Wadje
Mukesh KumarPosted Nov 22, 2015, 11:45 PM
Good Job Sir
kalu singh raoPosted Nov 21, 2015, 1:31 PM
nice one
Vithal WadjePosted Nov 3, 2015, 1:46 PM
Thanks
Shobhit KaushikPosted Nov 3, 2015, 12:03 PM
very good
Vithal WadjePosted Oct 13, 2015, 4:13 AM
Thanks
Pradip RupaliyaPosted Oct 13, 2015, 2:20 AM
It is an awesome article.. It becomes a very useful to me... Thank you so much. Vithal Wadje.
Vithal WadjePosted Sep 25, 2015, 4:24 PM
welcome
DarinPosted Sep 25, 2015, 8:37 AM
Thanx for the code buddy !!
Vithal WadjePosted Sep 16, 2015, 7:11 AM
Thanks
Igharosa PercyPosted Sep 14, 2015, 5:36 PM
Nice one
Vithal WadjePosted Sep 6, 2015, 2:38 AM
Welcome
Abhijeet ChavanPosted Sep 5, 2015, 3:11 PM
thanks
Vithal WadjePosted Aug 1, 2015, 7:14 AM
thanks Nitin Kaundal sir
Nitin KaundalPosted Jul 31, 2015, 6:06 AM
Very nice and helpful article sir ji.
Vithal WadjePosted Jul 17, 2015, 11:56 PM
Hi Mukhtar check the what are process to call in java
Mukhtar AhmadPosted Jul 13, 2015, 2:24 PM
sir, how can i consume it in a java web application??
Vithal WadjePosted May 30, 2015, 2:23 PM
thanks sir
Santhakumar MunuswamyPosted May 30, 2015, 1:03 PM
Thanks for good show
Vithal WadjePosted May 21, 2015, 8:05 AM
thanks
Appa TawalePosted May 21, 2015, 6:06 AM
Very Nice Article
Vithal WadjePosted May 11, 2015, 2:08 PM
thanks bmgn,
Vithal WadjePosted May 9, 2015, 5:32 AM
thanks Venkatesh Maddireddy sir
Former memberPosted May 9, 2015, 2:05 AM
bmgn,
Venkatesh MPosted May 9, 2015, 1:51 AM
Nice article sir
Vithal WadjePosted May 8, 2015, 1:13 PM
thanks
Yogendra YadavPosted May 8, 2015, 5:23 AM
nice
Vithal WadjePosted May 7, 2015, 1:25 PM
thanks
Upendra Pratap ShahiPosted May 7, 2015, 2:04 AM
nice article sir...
Vithal WadjePosted May 6, 2015, 7:49 AM
thanks
Vishwakant TripathiPosted May 6, 2015, 2:09 AM
nice article..
Karthik Muthu KaruppanPosted May 4, 2015, 2:20 PM
nice
Vithal WadjePosted May 2, 2015, 7:14 AM
thanks
Gowtham RajamanickamPosted May 2, 2015, 4:54 AM
good
Vithal WadjePosted May 1, 2015, 8:29 AM
Thanks Nitin sir
Vithal WadjePosted May 1, 2015, 8:29 AM
thanks Ratnesh Singh sir
NitinPosted May 1, 2015, 3:25 AM
nice one
Ratnesh SinghPosted May 1, 2015, 3:05 AM
nice ...
Vithal WadjePosted Mar 30, 2015, 2:24 PM
Thanks Abhijit Patil sir
Abhijit PatilPosted Mar 30, 2015, 5:45 AM
it s really a good startup for webservices Vithal Wadje (y)
Vithal WadjePosted Dec 10, 2014, 3:29 AM
thanks Sachin Patil sir
Sachin PatilPosted Dec 10, 2014, 2:09 AM
Thanks vithal oncs again
Vithal WadjePosted Dec 5, 2014, 12:10 AM
thanks Ramendra kumar verma sir
Ramendra kumar vermaPosted Dec 4, 2014, 5:22 AM
nice explain
Vithal WadjePosted Nov 20, 2014, 9:34 AM
thanks sir
Manish Kumar ChoudharyPosted Nov 20, 2014, 7:24 AM
Nice once Vithal Wadje sir..
Vithal WadjePosted Nov 20, 2014, 7:22 AM
thanks
Dhanya NarayananPosted Nov 20, 2014, 6:36 AM
Thanks abhijith sir.. nyc article..
Vithal WadjePosted May 20, 2014, 12:13 PM
thanks Abhijeet sir
Abhijeet ChavanPosted May 19, 2014, 11:07 PM
nice artical sir..
Vithal WadjePosted May 19, 2014, 2:03 PM
thanks
Abhijit PatilPosted May 19, 2014, 9:55 AM
nice artical vithal sir ,easy and clearly understanding
Vithal WadjePosted May 18, 2014, 6:01 AM
thanks Hussain Ahmed sir
Hussain AhmedPosted May 16, 2014, 8:44 AM
simple and essay.good work
Vithal WadjePosted Dec 10, 2013, 10:13 AM
thanks Sourabh
Sourabh SomaniPosted Dec 10, 2013, 12:16 AM
great sir ji very nice
Vithal WadjePosted Jun 6, 2013, 10:12 AM
Thanks Rohatash Sir,also you keep posting
Rohatash KumarPosted Jun 5, 2013, 11:12 PM
nice article vithal
Vithal WadjePosted May 20, 2013, 3:43 PM
thanks vishnu
Vishnujeet KumarPosted May 20, 2013, 3:34 AM
Very Nice .
Vithal WadjePosted Apr 19, 2013, 12:00 AM
thanks anurag sir
Anurag SarkarPosted Apr 18, 2013, 3:55 PM
Thanx Nice Coding.