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
- Add a reference to the service so the client can see its methods.
- Create an instance of the generated proxy class.
- 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.