CacheDuration Property Does Not Work
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.webservices.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Michael
I have a simple Web Method:

[WebMethod (CacheDuration=60)]
public string Date()
{
return DateTime.Now.ToString();
}

A new value for DateTime is always returned instead of the value being cached
for 60 seconds. This Web service is running on Windows Server 2003 Standard.
Is
there anything that has to be set to get to this to work?

Reply to this message...
 
    
[MSFT] (VIP)
Hello,

I tested your code also on Windows 2003 (and with VS.NET 2003), the value
is indeed cached for 60 seconds. Here is my client code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim ls As New localhost.Service1

MsgBox(ls.Date())

End Sub

As you see, everytime I click the button, it will return same result in 60
seconds.

If there any other configration for ASP.NET in your project? If you create
a new web service project and add same code, will it work?

Luke

Reply to this message...
 
    
Michael
I originally tried this using Internet Explorer as the client program and the
caching
did not work. This was verified on machines with Windows 2003 and XP. When
I read your reply, I decided to try using a a proxy generated class. The
caching works using the proxy.

Why should the caching work in one case and not the other? If one were
to use the Cache property of HttpContext would it work in both cases?

"[MSFT]" wrote:

[Original message clipped]

Reply to this message...
 
    
[MSFT] (VIP)
Did you run the web service directly from IDE? This may cause the problem.
You may open some IE windows out VS IDE, and browse to the link like:

http://localhost/WebService1/Service1.asmx/Date

You will see they give same result.

Luke

Reply to this message...
 
    
Michael
It DOES NOT work when IE is used to access the web service whether from
inside the IDE or outside. It works with a proxy based client. This has been
verified on two machines. One was running XP Pro, the other Windows 2003.

Why would it matter if I ran IE from inside the IDE. The caching happens
inside ASP.NET somewhere.

Michael

"[MSFT]" wrote:

[Original message clipped]

Reply to this message...
 
    
[MSFT] (VIP)
Hi Michael,

I not sure why it didn't work on your side. But it indeed works on my
Windows 2003 server. Please see the image in this message.

Here is my web service code:

[WebMethod (CacheDuration=60)]
        public string Date()
        {
            StringBuilder sb = new StringBuilder("Hi ");
        
            sb.Append(", the Cache entry was made at ");
            sb.Append(System.DateTime.Now.ToString());
            
            return(sb.ToString());
            
        }

All configrations in web.config is left as default value. Is this same with
yours? If you create a new web service project, will it work for you?

Luke
Reply to this message...
 
    
[MSFT] (VIP)
Hi Michael,

Did you create a simple project and try my code? What is the result you got?

Luke

Reply to this message...
 
    
Michael
No it still does not work when I use Internet Explorer as the client.

As before, it works with a proxy generated client.

As I mentioned in my previous posts, this behavior has been duplicated on
different machines running Windows XP and Windows 20003.

"[MSFT]" wrote:

[Original message clipped]

Reply to this message...
 
    
[MSFT] (VIP)
Hello,

If you add following line in the web method code:

this.Context.Response.AddHeader("Cache-Control","max-age=\"10000\"");

Will this cause a didferent result?

Luke

Reply to this message...
 
    
Michael
No.

Michael

"[MSFT]" wrote:

[Original message clipped]

Reply to this message...
 
    
[MSFT] (VIP)
Hi Michael,

Can you send me your project for research? To get my actual email address,
please remove "online".

Regards,

Luke

Reply to this message...
 
    
Michael
It has been sent.

Thanks.

Michael

"[MSFT]" wrote:

[Original message clipped]

Reply to this message...
 
    
[MSFT] (VIP)
Hi Michael,

I haven't received it yet. My email address is lukezhan(a)microsoft.com.
Did you sent the file to it?

Thanks,

Luke

Reply to this message...
 
    
Michael
Yes I sent it yesterday morning.

I just sent it again.

Michael

"[MSFT]" wrote:

[Original message clipped]

Reply to this message...
 
    
[MSFT] (VIP)
Hi Michael,

I not sure why I still haven't received it yet. You may resend it to my
email box on hotmail: Click here to reveal e-mail address. Thank you for your patience.

Luke

Reply to this message...
 
    
Michael
I sent the files over. I never got an undeliverable email message from the 2
emails I sent.

Michael

"[MSFT]" wrote:

[Original message clipped]

Reply to this message...
 
    
[MSFT] (VIP)
Hi Michael,

I dtill didn't receive it yet. I have sent you an email. Please replied it
and send the files. Also, you may upload files in the post and I can
download it.

Luke

Reply to this message...
 
    
[MSFT] (VIP)
Got it finally. I will perform some test and let you know the result.

Thanks,

Luke

Reply to this message...
 
 
System.DateTime
System.EventArgs
System.Object
System.Text.StringBuilder
System.Web.HttpContext




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com