Use of Web service proxy classes

Source: Internet
Author: User
Tags command line web services wsdl
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 ();




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.