ARTICLE

Simplest way to Create and Deploy Web Services

Posted by Rajadurai P Articles | Web Services in C# August 20, 2001
This article explains how to create and deploy a simple Web Service.
Reader Level:

Introduction

Tools Used: .net SDK

How to use: This article explains how to create and deploy a simple webservice .
To use the sample code, one needs to have .net SDK installed. A text editor is enough to build and test the codes.

Creating a Simple Web Service

  1. Create a folder named Webservice under wwwroot.
  2. Create a File

    <%@ WebService Language="c#" Class="AddNumbers"%>
    using System;
    using System.Web.Services;
    public class AddNumbers : WebService
    {
    [WebMethod]
    public int Add(int a, int b)
    {
    int sum;
    sum = a + b;
    return sum;
    }
    }
  3. Save this file as AddService.asmx [asmx-> file extension]
  4. Now the webservice is created and ready for the clients to use it.
  5. Now we can call this webservice using http://ip address/Webservice/Addservice.asmx/Add?a=10&b=5

This will return the result in XML format.

Deploying the Web Service on the Client Machine

  1. At the command prompt:
    WSDL
    http://ip address ofthe site/WebService/MathService.asmx /n:NameSp /out:FileName.cs
    This will create a file called FileNmame.cs.

    WSDL -> WebServices Description Language (This is an application available at C:\Program  Files\Microsoft.NET\FrameworkSDK\Bin)

    NameSp -> Name of the NameSpace which will be used in client code for deploying the webservice.

  2. Compilation
    CSC /t:library /r:system.web.dll /r:system.xml.dll CreatedFile.cs
    This will create a dll with the name of the public class of the asmx file.(In our case,  it is "AddNumbers.dll").
    CSC is an application available at C:\WINNT\Microsoft.NET\Framework\v1.0.2914

  3. Put the dll file inside WWWRooT\BIN [Create a BIN Folder in WWWRoot].

Making use of WebService in client asp/aspx page

<%@ import Namespace = "NameSp" %>
<script language = "c#" runat = "server">
public void Page_Load(object o, EventArgs e){
int x = 10;
int y = 5;
int sum;
//Instantiating the public class of the webservice
AddNumbers AN = new AddNumbers();
sum = AN.Add(x,y);
string str = sum.ToString();
response.writeline(str);
}
</script>

Note: It is advisable to

  1. Copy the .asmx file to the folder containing WSDL aplication (C:\Program  Files\Microsoft.NET\FrameworkSDK\Bin) before creating cs file.

  2. Copy the created .cs file to the folder containing CSC application (C:\WINNT\Microsoft.NET\Framework\v1.0.2914) before compliling it.

Login to add your contents and source code to this article
post comment
     

can u tell me how to deploy a web service in IIS in a local machine?

Posted by janani brindha Apr 13, 2010

what is parsel class in asp.net 2.0 , how to use in real time projects , could you expalin clearly .

Posted by purna chandra Jun 06, 2007
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter