You are on page 1of 3

Steps for making Asp.

net Web-service

1. Project->Add Component ->Web Service->Add

A web service file creates with asmx extension. Containting web Method Hello
World.

2. add another web Method say square

[WebMethod]
public string square(int x)
{
String s = "";
int y = x * x;
s = y.ToString();
return s;
}

3. Generate a proxy Class for Web Service using WSDL Exe file at location

C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\wsdl.exe

With the following command

wsdl /l:CS /protocol:SOAP http://localhost:2188/WebService2.asmx?WSDL

where 2188 is port number . it will depend upon machin. Yuou can get it by running your
web application.

The WebService2.cs File Generates at following Folder

C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin.

4. Compile the Proxy Class as a DLL Library using csc.exe being at location

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe Firstly copy

Your WebService2.cs File to above address. Ie.

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

Set command prompt to this path using

Cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
Run Following command
csc /t:library /r:System.Web.Services.dll /r:System.Xml.dll WebService2.cs

As output:-
WebService2.dll generates at location
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

5. Copy WebService2.dll to you projects Bin Folder.

6. Make The following button coding

protected void Button1_Click(object sender, EventArgs e)


{
WebService2 s = new WebService2();
String p = s.square(4);
Response.Write(p);

Response.Write(s.HelloWorld());
}

You might also like