Skip to main content
CSharpUniversity ASP.NET and C# lessons

The search runs entirely in your browser over the published lesson list.

Calling a web service from a page

A client page does not need to know how a service is built. It needs the service address and a reference to its methods.

Add the reference, then call

C#
var service = new ProductService();
DataTable table = service.GetProducts("tools");

productsGrid.DataSource = table;
productsGrid.DataBind();

The steps

  1. Add a reference to the service so the client can see its methods.
  2. Create an instance of the generated proxy class.
  3. Call the method and bind the result.
Plan for failure. A service call crosses a network, so it can time out or be unavailable. Wrap the call so a slow service does not take your page down with it.

When the service itself changes, the client must be refreshed. That is updating a client when the service changes.

New lessons by email

Leave your address and get a short note whenever a fresh lesson is published. No account needed and you can stop at any time.

Thank you. Your address has been noted in this browser session. Connect a mailing service to deliver the notes for real.