Classes that include public attributes and domains are passed back and forth between applications and WEB Services. This function is useful when processing structured data:
By creating a WEB Service proxy class to access the WEB service in the application, the essence is the local representation of the properties and methods of the remote WEB service class
By the way, write the usage process:
1> Create a WEB Service Project and rename a service file: myProductSerivce. asmx
2> write code in myProductSerivce. asmx:
Write your WEB service method:
For example:
[WebMethod (CacheDuration = 30, Description = "this is a WEB service that returns DataSet! ")]
Public DataSet GetProducts ()
{
String constr;
Constr = "server = MICROSOFT-LAB2; user id = sa; password =; database = Northwind ";
String SQL;
SQL = "select top 10 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> after creating a Web service, run wsdl.exe to generate a proxy class for the service:
Wsdl/l: cs http: // localhost/myProductService. asmx? WSDL
4> then, execute the following CS command; Compile the proxy class (use the above command to convert this service into a class file)
Csc/t: library/r: System. dll, System. Web. Services. dll, System. xml. dll, System. Data. dll
MyProductService. cs
5> reference the DLL created above in the ASP. NET project, and add a reference to system. web. services.
In this case, you can use it in the code, just as before to call his method:
For example:
MyProductService mypro = new myProductService ();
DataGrid1.DataSource = mypro. GetProducts ();
DataGrid1.DataBind ();