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