Share via


方法 : Web サービス クライアントで出力キャッシュを有効にする

このトピックの対象は、レガシ テクノロジに特定されています。XML Web サービスと XML Web サービス クライアントは以下を使用して作成してください。 Windows Communication Foundation.

次のコード例では、クライアント アプリケーションで Duration プロパティを使用して、出力キャッシュ時間を 60 秒間に指定する方法を示します。この例は、「ASP.NET を使用して作成する XML Web サービスのデザイン ガイドライン」で説明されているガイドラインの 1 つを示しています。

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<%@ OutputCache Duration="60" VaryByParam="none" %>
<html>
   <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),
                              Convert.ToInt32(Num2.Text));
         // Display the results in a Label control.
         Total.Text = "Total: " + total.ToString();
      }
   </script>
<body>
   <form action="MathClient.aspx" runat=server>
      <font face="Verdana"> 
         Enter the two numbers you want to add and press 
         the Total button.
         <p>
         Number 1: 
         <asp:textbox id="Num1" 
         runat=server/>  
         +
         Number 2: 
         <asp:textbox id="Num2" 
              runat=server/> 
         =
         <asp:button id="Total_Button"
              text="Total" 
              OnClick="EnterBtn_Click" 
              runat=server/>
         <p>
         <asp:label id="Total" runat=server/>
      </font>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net" %>
<%@ OutputCache Duration="60" VaryByParam="none" %>
<html>
   <script language="VB" runat="server">
      Sub EnterBtn_Click(Src As Object, e As EventArgs) 
         Dim math As New MyMath.Math()
         ' Call the Web service.
         Dim addtotal As Single = math.Add(Convert.ToInt32(Num1.Text), _
                              Convert.ToInt32(Num2.Text))
         ' Display the results in a Label control.
         Total.Text = "Total: " & addtotal.ToString()
      End Sub
   </script>
<body>
   <form action="MathClient.aspx" runat=server>
      <font face="Verdana"> 
         Enter the two numbers you want to add and press 
         the Total button.
         <p>
         Number 1: 
         <asp:textbox id="Num1" 
         runat=server/>  
         +
         Number 2: 
         <asp:textbox id="Num2" 
              runat=server/> 
         =
         <asp:button id="Total_Button"
              text="Total" 
              OnClick="EnterBtn_Click" 
              runat=server/>
         <p>
         <asp:label id="Total" runat=server/>
      </font>
    </form>
</body>
</html>

参照

処理手順

方法 : Web サービスのサーバー側の出力キャッシュを有効にする

概念

ASP.NET を使用して作成する XML Web サービスのデザイン ガイドライン