Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Monday, 20 March 2017

Create A Web Service In Asp.Net Using Visual Studio 2015

 Webservice     No comments   



Introduction
In this post we will learn about how to create a Web Service in asp.net using Visual Studio 2015. How to run service project and also detail about the basic terms used in Service like WebMethod etc.


Description
 VS 2015 doesn't allows you to create a Web Service project like VS 2010, 12 etc.  Microsoft update its VS-15 with new features . Peoples are very rarely use the web service in  today's modern world. Because we have a Web Api concept also WCF service. 
But many times you only have a small service requirement ,for these situation this post will be the best understanding explanation for you about the service creation in c# asp.net.
As we already talked about Web Service basics in previous update about service.


Practice
Here we create a Web Service in 4 simple steps. 

1.  Open VS2015  and Create a New WebSite . Select an Empty Website template ,give a suitable name to it ( in my example its name DemoWebService ) and click OK.


2.  After creating new WebSite goto Solution Explorer , select Website Name and right click, select Add New Item and select WebService type page. give a suitable name to this . Here i named this TestService.


 After adding webService page your code looks like this


3. Remove given Web Method if you don't want to use this and create your own method based upon your requirement. Here i create a AgeCalulator method named GetAge.


[WebMethod]
  public string GetAge(DateTime Dob)
  {
      DateTime PresentYear = DateTime.Now;

      TimeSpan ts = PresentYear - Dob;
      int Age = ts.Days / 365;
      return Age.ToString(); 
  }


GetAge method will return age in year  and accept the datetime  type of input variable as a parameter. 

4. Build Project and right click on your asmx page and choose Setas StartPage and Run the                     Application.



You will find the similar type of screen in front of you after running the application. And its all done, you have successfully created a Web Service just in 4 simple steps. 

Test Web Service 
Click on the method which created earlier in my example it is GetAge 

As we can see i used Dob as parameter name in my WebMethod and in the above image it is clearly shown field name Dob. Enter any Dob in DD/MM/YY format and click on Invoke Button.
Here is the output given by the web service which is 21 conversion of given DOB.

<string xmlns="http://gurujipoint.com/">21</string>

You can add as many methods you want in this service and use these wherever you want in any application by giving your service reference. In my next article i will explain you how to consume this web service.

Points To Remember  :-
  • Web Service is a communication platform between two same or different platform application.
  •  Method in Web service always start with Web-Method attributes which tells about it is a web method which is accessible from anywhere in application.






  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write