17.8 Consuming Web Services with ASP.NET Applications

 <  Day Day Up  >  

You want to consume a Web Service with an ASP .NET application.


Consuming a Web Service from an ASP.NET application uses the same methods shown in the previous recipe. After you add a Web reference, you can access a proxy class within the code-behind file of your Web application.


Recipe 17.2, "Adding Web Service Methods," said that Web Service methods are only able to use a subset of the data types within the .NET framework. They are usually limited to the normal value types such as strings and integers as well as arrays of value types, but you can also return a DataSet object, which makes Web Services suitable as a data source for ASP.NET applications. For example, a Web Service that returns a DataSet representing the Products table from the Northwind SQL database could be consumed by an ASP.NET DataGrid control, as shown in the following code:

 private void Page_Load(object sender, System.EventArgs e) {     if( !Page.IsPostBack )     {         localhost.ProductsService northwind = new localhost.ProductsService();         DataGrid1.DataSource = northwind.GetProducts();         DataBind();     } } 
 <  Day Day Up  >  

Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net