방법: 웹 서비스 클라이언트에서 출력 캐싱을 사용하도록 설정

다음 코드 예제에서는 클라이언트 응용 프로그램의 Duration 속성을 사용하여 60초 동안 출력 캐싱을 지정하는 방법을 보여 줍니다. 이 예제에서는 Design Guidelines for XML Web Services Created Using ASP.NET 항목에서 설명하는 지침 중 하나를 보여 줍니다.

예제

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<%@ OutputCache Duration="60" VaryByParam="none" %>
<html>
   <script language="C#" >
      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" >
      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>

참고 항목

작업

방법: 웹 서비스의 서버측 출력 캐싱을 사용하도록 설정

개념

ASP.NET을 사용하여 만든 XML Web services에 대한 디자인 지침

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.