Export (0) Print
Expand All

Client Application for Web Service (EDM Sample Application)

.NET Framework 3.5

Visual Studio makes it easy to create client applications that use Web services. The application in this example uses the BooksAuthors Web service created in other topics in the Entity Data Model (EDM) section. For implementation details, see Books Authors Web Service Implementation (EDM Sample Application).

To use the BooksAuthors Web service, create a new project by using the ASP.NET Web Site template in Visual Studio. Add a Web Reference to the BooksAuthors Web service. This may be a temporary development server location or a published location on a Web server. Supplying a name for the Web Reference provides a variable that can be accessed from code. No references are necessary to the schemas or DLL that contain the entities and associations that are used by the Web service. The Web Reference name is used to locate all the methods provided by the service.

Application Code

The following example uses a GridView control on a Web page. When the page loads, an instance of the Web service is created. An array of XML objects based on Books entities used by the Web service is obtained by using the GetBooks method. The array of books is assigned to the DataSource property of the GridView control. Calling GridView1.DataBind() loads the array into the control for display.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BooksAuthorsService.Service booksAuthors = new
                              BooksAuthorsService.Service();


        GridView1.DataSource = booksAuthors.GetBooks();
        GridView1.DataBind();
 
  
    }
}

The running client application that has data displayed in the GridView control is shown in the following screen display.

Results of GetBooks Web Service Method

See Also

Community Additions

Show:
© 2015 Microsoft