Use of WEB Service Proxy

Source: Internet
Author: User


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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.