Click here to Skip to main content
13,193,600 members (64,820 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 21 Apr 2016

[You can do it] How to Create a Web service in ASP.NET

, 21 Apr 2016
Rate this:
Please Sign up or sign in to vote.
A web service is a web application (a piece of software component) which is available on the internet.


In this article, you will learn what is a web service in ASP.NET, how it communicates with the other web applications and how to create a web service in ASP.NET.

What is a Web Service

A web service is a web application (a piece of software component) which is available on the internet. A web service uses XML format for all the communication with other applications on the internet. It uses XML and JSON data formats and HTTP protocol to communicate with other applications over the internet.

For example, let's say I have created a web application that can convert a string into uppercase. If I want it to be used by other applications on the internet, then it has to be converted into a web service and should be deployed on the net.

In the next few lines, you will see how to create a web service in ASP.NET and how to use it:

Step 1: Create a web service file and name it "HelloWorld.asmx" in Visual Studio. The extension for a web service file is .asmx:

Step 2: After you have created the web service file, a code file "HelloWorld.vb" will be created in App_Code folder.

Step 3: Open this code file and write your custom code for the web service functionality. This web service will return a "Hello World" when it is consumed"

1.Imports System.Web
2.Imports System.Web.Services
3.Imports System.Web.Services.Protocols
5.' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
6.' <System.Web.Script.Services.ScriptService()> _
7.<WebService(Namespace:="")> _
8.<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
9.<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
10.Public Class HelloWorld
11.     Inherits System.Web.Services.WebService
13.    <WebMethod()> _
14.    Public Function HelloWorld() As String
15.        Return "Hello World"
16.    End Function
18.End Class 

Step 4: Okay. The service is created but how to use it. To use this service, create a simple .aspx page and paste the following code in it. In the action part, put the location of the web service. Here I have used my local host URL. Replace action part with your web service URL.

1.<%@ Page Language="VB" AutoEventWireup="false" 

CodeFile="HelloWorld.aspx.vb" Inherits="HelloWorld" %>
3.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

5.<html xmlns="">
6.<head runat="server">
7.    <title></title>
10.    <form id="form1" runat="server" 

action="http://localhost:49572/wsDemo/HelloWorld.asmx/HelloWorld"  method="POST">
11.        <input type="submit" value="Run Web Service"> </input>
12.    </form>

Step 5: Here is the final output "Hello World" in the form of XML. You can read this XML data to use in your program.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Subodh Raghav, a Software Architect and certified web enthusiast, acquired his formal education and training at Aligarh Muslim University, India. He holds a Masters Degree in Computer Application and as of the present time; takes pride in working in the I.T. industry.

Subodh’s first article had been featured and published in and among many others. As a programming enthusiast and a self-confessed “programming addict”, he has created various software applications to maximize the lifestyles of the modern internet users and other people who share his passion for computer technology. With over 60 original posts in his blog, he continues to impart his expertise to others by way of posting new and valuable information that can make a major difference in people’s lives.

Subodh’s hobbies and personal interests include writing informative blogs and surfing the internet; and he also takes inspiration from music and physical sports such as Cricket. Currently, he works for a IT Company in Noida, India; and is the author of his own blog.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 2 Pin
Gregory.Gadow5-Feb-14 5:49
memberGregory.Gadow5-Feb-14 5:49 
GeneralRe: My vote of 2 Pin
JV99996-Feb-14 3:47
professionalJV99996-Feb-14 3:47 
SuggestionYour article does not present a clear idea, but it is not bad. Pin
Hamza I. Kanaan5-Feb-14 1:40
professionalHamza I. Kanaan5-Feb-14 1:40 
SuggestionPretty much for beginner Level only. but a nice try. Pin
VICK4-Feb-14 19:41
member VICK4-Feb-14 19:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171018.2 | Last Updated 22 Apr 2016
Article Copyright 2016 by Subodh Raghav
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid