日期:2008-07-18 浏览次数:20554 次
使用输出缓冲来改善你的XML Web服务的性能。当输出缓冲开启时,服务请求的结果被保存在输出缓冲中一段指定的时间。如果一个类似的XML Web服务请求被产生,结果可以从缓冲中取得,而不用重新计算。这样就通过减少XML Web服务服务器所需的处理来改善了XML Web服务的反馈时间。高速缓存可在客户端和服务器两者上执行。Duration属性允许你指定高速缓冲保存XML Web服务输出的时间。
在客户端上使用输出高速缓冲的指令是:
<%@ OutputCache Duration="60" %> |
[C#] <%@ 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 XML 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> [Visual Basic] <%@ 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 XML 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> |
[C#] <%@ WebService Language="C#" Class="MathService" %> using System; using System.Web.Services; public class MathService : WebService { [WebMethod(CacheDuration=60)] public float Add(float a, float b) { return a + b; } [WebMethod(CacheDuration=60)] public float Subtract(float a, float b) { return a - b; } [WebMethod(CacheDuration=60)] public float Multiply(float a, float b) { return a * b; } [WebMethod(CacheDuration=60)] public float Divide(float a, float b) { if (b==0) return -1; return a / b; } } [Visual Basic] <%@ WebService Language="VB" Class="MathService" %> Imports System Imports System.Web.Services Public Class MathService Inherits WebService <WebMethod(CacheDuration := 60)> _ Public Function Add(a As Single, b As Single) As Single Return a + b End Function <WebMethod(CacheDuration := 60)> _ Public Function Subtract(a As Single, b As Single) As Single Return a - b End Function <WebMethod(CacheDuration :
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
|