Web|web Service
A class that contains public properties and domains is passed back and forth between applications and Web services, which is useful when working with structured data:
Accessing a Web service within an application by creating a Web service proxy class is essentially a local representation of the properties and methods of the remote Web service class
By the way, write down the usage process:
1> first set up a Web service project to rename a service file: Myproductserivce.asmx
2> Write code in Myproductserivce.asmx:
Write your Web service method:
Such as:
[WebMethod (cacheduration=30,description=) This is a Web service that returns a DataSet! ")]
Public DataSet getproducts ()
{
String Constr;
Constr= "Server=microsoft-lab2;user Id=sa; password=; Database=northwind ";
String sql;
Sql= "SELECT top productname,unitprice,discontinued from Products";
SqlConnection mycon=new SqlConnection ();
Mycon. ConnectionString =constr;
SqlDataAdapter Myadp=new SqlDataAdapter (Sql,mycon);
DataSet ds=new DataSet ();
Myadp. Fill (DS);
Mycon. Close ();
Myadp. Dispose ();
return DS;
}
3> The Web service is created, the Wsdl.exe tool is then executed at the command line to generate a proxy class for the service:
Wsdl/l:cs Http://localhost/myProductService.asmx?WSDL
4> then, execute the CS command below; Compile the proxy class (the service is converted to a class file by the command above)
CSC/T: Library/r:system.dll,system.web.services.dll,system.xml.dll,system.data.dll
MyProductService.cs
5> references the DLL created above in the ASP.net project, and adds a reference to System.Web.Services
You can then use it in your code, just like before, calling his methods:
Such as:
Myproductservice mypro=new Myproductservice ();
DataGrid1.DataSource =mypro. GetProducts ();
Datagrid1.databind ();