A web service is a web application that is basically a class consisting of methods that could be used by other applications on the “http://” protocol. It also follows a code-behind architecture like the ASP.NET web pages, although it does not have a user interface.It's an alternate option of C# Remoting Architecture, in Remoting we can communicate from a server to a client on tcp:// channel but there should be .NET framework installed on both ends, on the server and also on the client side because the server returns an object in Plane Old CLR Object (POCO) format that is only understandable by CLR.A web service class can be a collection of web methods with return types that can serializable directly as XML or JSON.Create a simple WebService Application in Visual Studio using the following procedure.Step 1: Open Visual Studio then go to File -> New -> Web Site.Step 2: Select HTTP Web Location and write a name for "ASP.NET Empty Web Site".Step 3: Go To Solution Explorer and right-click the project then select Add New Time -> Web Service.Step 4: Write a name for the Web Service file and then it will add a file for the web site with “.asmx “ (Active Server Method Extension) extension and also add a code file (.cs/.vb) .Then add a web Service .Step 5: Delete the .cs File from App_Code and add a new class file to create a Code Behind file from .asmx file to host a web service class.Step 6:Use “using System.Web.Services; “ first to use the [WebService] and [WebMethod] attributes.[WebService]: This attribute defines the class that we need to host by “.asmx” file and a client-side proxy class is necessary to create the same structure of this class.[WebMethod]: This attribute defines the method that we can call from the client side by the URL of my WebService class and it also serializes the return value of the method in the format of XML or JSON.Step 7: Finally edit your “.asmx “ file To define the the object of the WebService class with a property like:
Step 8: Now build your WebService application and right-click on “.asmx” and view in the browser.Then the following output will be in the browser.There will be a list of all the methods declared by the attributes [WebMethod] in the [webService] class. We can test all the [WebMethod] attributes on the local system where my Web Service Application is hosted by the click on the method name.Pass all the formal parameter values into the TextBox and click to test the return value of this method in the format of XML by default. If you want to return JSON data we will learn about that in the next article.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: