Introduction to Web Service

Category: WEB SERVICE Comments: 2 comments

Web Service is an application that is designed to interact directly with other applications over the internet. In simple sense, Web Services are means for interacting with objects over the Internet. The Web serivce consumers are able to invoke method calls on remote objects by using SOAP and HTTP over the Web. WebService is language independent and Web Services communicate by using standard web protocols and data formats, such as

  • HTTP
  • XML
  • SOAP
Advantages of Web Service
Web Service messages are formatted as XML, a standard way for communication between two incompatible system. And this message is sent via HTTP, so that they can reach to any machine on the internet without being blocked by firewall.
Examples for Web Service
Weather Reporting: You can use Weather Reporting web service to display weather information in your personal website.
Stock Quote: You can display latest update of Share market with Stock Quote on your web site.
News Headline: You can display latest news update by using News Headline Web Service in your website.
In summary you can any use any web service which is available to use. You can make your own web service and let others use it. Example you can make Free SMS Sending Service with footer with your advertisement, so whosoever use this service indirectly advertise your company… You can apply your ideas in N no. of ways to take advantage of it.
Frequently used word with web services
What is SOAP?
SOAP (simple object access protocol) is a remote function calls that invokes method and execute them on Remote machine and translate the object communication into XML format. In short, SOAP are way by which method calls are translate into XML format and sent via HTTP.
What is WSDL?WSDL stands for Web Service Description Language, a standard by which a web service can tell clients what messages it accepts and which results it will return.

WSDL contains every detail regarding using web service and Method and Properties provided by web service and URLs from which those methods can be accessed and Data Types used.
What is UDDI?
UDDI allows you to find web services by connecting to a directory.
What is Discovery or .Disco Files?
Discovery files are used to group common services together on a web server. Discovery files .Disco and .VsDisco are XML based files that contains link in the form of URLs to resources that provides discovery information for a web service. Disco File contains URL for the WSDL, URL for the documentation and URL to which SOAP messages should be sent.


Some Issues are

  • Component-based programming has become more popular For example end-to-end e-commerce solution residing on a Web farm needs to submit orders to a back-end Enterprise Resource Planning (ERP) application that resides on different hardware and might run on a different operating system. The Microsoft Distributed Component Object Model (DCOM), a distributed object infrastructure that allows an application to invoke Component Object Model (COM) components installed on another server, has been ported to a number of non-Windows platforms. But DCOM has never gained wide acceptance on these platforms, so it is rarely used to facilitate communication between Windows and non-Windows computers. ERP software vendors often create components for the Windows platform that communicate with the back-end system via a proprietary protocol.

  • Some services related to application For example, if the e-commerce application accepts credit card payment for goods purchased by the customer, it must elicit the services of the merchant bank to process the customer’s credit card information. But for all practical purposes, DCOM and related technologies such as CORBA and Java RMI are limited to applications and components installed within the corporate datacenter. Two primary reasons for this are that by default these technologies leverage proprietary protocols and these protocols are inherently connection oriented.

  • Interoperability, The remote service must be able to be consumed by clients on other platforms.

  • Internet friendliness, The solution should work well for supporting clients that access the remote service from the Internet.

  • Strongly typed interfaces, There should be no ambiguity about the type of data sent to and received from a remote service.

  • Ability to leverage existing Internet standards

  • Support for any language Support for any distributed component infrastructure, The solution should not be tightly coupled to a particular component infrastructure. In fact, you shouldn’t be required to purchase, install, or maintain a distributed object infrastructure just to build a new remote service or consume an existing service. The underlying protocols should facilitate a base level of communication between existing distributed object infrastructures such as DCOM and CORBA.


1. Create the Web Service

First create new project and select “New ASP.NET Web Service Application” and I’m giving the name “MyFirstWebService” to it, you can give any name to your project.

Now you can see auto generated code that you can add methods to create your web service. You can see simple method “HelloWorld” and in this sample code I have removed it.

I’m going to add simple method called “simpleMethod” which takes a string as an input and add “Hello” to beginning of that string. Now the code will appear like bellow.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace MyFirstWebService
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "")]
[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 Service1 : System.Web.Services.WebService
public string simpleMethod(String srt)
return “Hello “+srt;

public int anotherSimpleMethod(int firstNum, int secondNum)
return firstNum + secondNum;


Then you can run your code and you can see the resulting page as bellow.


2. Create the Client Program


We have created our simple web service and we have to create small
client program to use this web service. There you can open another
instant of Visual Studio and create new “Console Application” project.


Then you have to add Service Reference so that you can access your web service. Here are the screen-shots.




Here you have to give the URL of the web service we created earlier.
As I said before previously created web service application should be
running on another instant of Visual Studio.


web service article

Note that I have set the “Web reference name” as “TestWeb”.

Now you can update your client program using following code. Note the line 5 “using WebServiceTest.TestWeb;”.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebServiceTest.TestWeb;

namespace WebServiceTest
class Program
static void Main(string[] args)
Service1 webservice = new Service1();
string srt = webservice.simpleMethod(“Saranga Rathnayake”);
Console.WriteLine(webservice .anotherSimpleMethod(4,3));

Now you can run the client program to see the result.


3. Publish Our Web Service in Internet Information Service (IIS)

Let’s see how we can publish our web service in IIS. Otherwise you always need to run your web service application in separate VS instant. There first stop the web service application and go to the Solution Explore and Right Click on the project. Then select “Publish…”.

Then the following window will appear and there you can directly publish to the IIS by selecting “Web Deploy” as the publishing method. But here I’m going to use the “File System as the publishing method. There you have to provide the target location. I have created new folder called “MyApp” in my D drive and selected it.

Now click “Publish” and check the “MyApp” folder. There you will be able to see Service1.asmx file, Web.config file and bin folder which contains the DLL file has been generated. Then copy this “MyApp” folder to “wwwroot” folder. You may find it in “C:\inetpub\wwwroot”.

Now enable IIS in your computer and open IIS Manager. I’m going to add my service to Default Web Site. There Right Click on the “Default Web Site” and click “Add Application…”.

There you will get following window. Now you can provide appropriate Alias (I have given testservice) and select the physical path of your application. There you can provide the path to the folder we copied previously as following figure and click Ok.

You have to make sure that the application pool identity has Read access to the physical path. So it is better if you copy your files to the “wwwroot” folder other than keep it in separate partition. Please check the following screen-shot


Now restart the IIS and goto http://localhost/testservice/Service1.asmx. You will be able to see the Web Service running.

Now you have published your web service in IIS and you can update the Client Program by giving the new Web Reference URL using Properties Window.

2 comments on “Introduction to Web Service

  1. O2infosystems on said:

    I just want to say that I like your posting. In fact I am using your site regularly. Your articles are very effective and i am very thankful to you for sharing this site with knowledgeable content .

Leave a Reply

Your email address will not be published. Required fields are marked *


HTML tags are not allowed.