There are few step to add a new web service to asp.net
-> First create a new web application.
-> Then go to your project and right click and see there is one option "Add Web References".
-> Then you got this type of pop up window on your screen and in this you enter your web
service url and click "go" button near the url text box. You give one name to your web service
say "Test" above the "Add Reference" button. then click this button and you see they create a
new folder in the "App_WebReferences" and in that floder they create your "Test" floder and
put your web service in this folder.
-> Now in you sample.aspx.cs page add reference of that web service this way.
using Test;
-> Now in pagload or any event you want to used this web service in your page this way. I write
in page load event. To print "Hello wrold".
protected void Page_Load(object sender, EventArgs e)
{
Service objservice = new Service();
Response.Write(objservice.HelloWorld());
}
-> Run This sample and you got this result.
Wednesday, July 2, 2008
Create a web service in asp.net
There are few step to create a new web service.
1) Create a new web service application say "TestService". In that you get "Service.asmx" file.
2) In "Service.asmx" file you got this type of content.
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service ()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
3) When you run this web service application you got this type of
Here you see there is one method "HelloWrold" and other detail of web service.
Click on this method and you get this type of content
In this there is one button "Invoke". When you clik that button you get result
of your web service.
Hello World
4) Take a path for your web service at this time your path like this
http://localhost:3406/TestService/Service.asmx
Or
If you deploy this web service into iis then you get different pathe like this
http://youeservername/TestService/Service.asmx
1) Create a new web service application say "TestService". In that you get "Service.asmx" file.
2) In "Service.asmx" file you got this type of content.
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service ()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
3) When you run this web service application you got this type of
Here you see there is one method "HelloWrold" and other detail of web service.
Click on this method and you get this type of content
In this there is one button "Invoke". When you clik that button you get result
of your web service.
4) Take a path for your web service at this time your path like this
http://localhost:3406/TestService/Service.asmx
Or
If you deploy this web service into iis then you get different pathe like this
http://youeservername/TestService/Service.asmx
Labels:
Web Service
Subscribe to:
Posts (Atom)