WebServices in ASP.net...?
In this article I'm trying to explain how to work with webservices and how to publish the webservices and how to call that webservices in our application with sample code snippet. May be this will help who are looking the same thing...
Creating ASP.net WebServices:
? ASP.net provides system.web.services namspace where we have a class called webservices.
? To create webservices we have to extend this class and write method init. These methods should be web methods, because a webservice is collection of webmethods.
? .asmx is the extension of this used to specified that we are creating web services.
Note: ASP.net webservices templates are lost provided in .net version 3.5, because from .NET 4.0 onwords WCF is used to preparing any type of distributed and service oriented Application.How to create a webservice:
File ? New Webservice ? .net 3.5 ? ASP.net WebserviceWhen we have to write our methods to services:
? Go to .cs file and write methods just like regular .net methods but before of that we just add [WebMethod] attribute. So, that these methods are SOAP oriented methods.
? Once methods are written then just right click on start debugging to start webservices as well as test webservices.
? Finally provide this URL to client. So, that theycan provide PROXY to communicate with services.Sample code:
DataLayer Class:
Public string Insert_Data(Parameters….)
{
//code for connect to database
}
Public DataSet Get_Data(parameters….)
{
//code for connect to database
}
WebServices
my webservice name is Design.
[WebMethod]
Public string Insert_Data(parameters…)
{
Dlayer obj= new Dlayer();
Return obj.Insert_Data(Parameter….);
}
Public DataSet Get_Data(parameters….)
{
Dlayer obj=new Dlayer();
Return obj.Get_Data(parameters….);
}
Presentation LAyer:
public void Get_Data()
{
Design obj=new Design();
DataSet ds= obj.Get_Data(parameters...);
GV.DataSource=ds;
GV.DataBind();
}
public void Insert()
{
Design obj=new Design();
string Result= obj.Insert_Data(parameters...);
}Conclusion:
Using this we can easily call the methods from DataAccessLayer and we can easily publish this WebService and call this WebService in our Application easily.