This documentation is archived and is not being maintained.

How to: Enable Output Caching on a Web Service Client

Visual Studio 2010

This topic is specific to a legacy technology. XML Web services and XML Web service clients should now be created using Windows Communication Foundation .

The following code example demonstrates how to use the Duration property on the client application to specify output caching for a period of 60 seconds. This example illustrates one of the guidelines explained in the topic, Design Guidelines for XML Web Services Created Using ASP.NET.


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<%@ OutputCache Duration="60" VaryByParam="none" %>
   <script language="C#" runat="server">
      void EnterBtn_Click(Object Src, EventArgs e) 
         MyMath.Math math = new MyMath.Math();
         // Call the Web service.
         float total = math.Add(Convert.ToInt32(Num1.Text),
         // Display the results in a Label control.
         Total.Text = "Total: " + total.ToString();
   <form action="MathClient.aspx" runat=server>
      <font face="Verdana"> 
         Enter the two numbers you want to add and press 
         the Total button.
         Number 1: 
         <asp:textbox id="Num1" 
         Number 2: 
         <asp:textbox id="Num2" 
         <asp:button id="Total_Button"
         <asp:label id="Total" runat=server/>

See Also