473,542 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StreamWriter invalidates web service cache: bug?

I insert a string in cache in a property set and I retrieve that string in
the get.

I retrieve my string with Read web method and I insert it with Write web
method: to try cache I do Read, Write, Read.

When I do the second Read, string is null if in the property set,
before/after inserting data into cache I write this code:

using (StreamWriter streamWriter = new
StreamWriter(@" D:\Log.txt"))
{
streamWriter.Wr ite(cacheValue) ;
streamWriter.Fl ush();
}

Debuggin the Write, in the watch windows I see the correct just inserted
value of cache.

The same behaviour persists if I write "Hello world" instead of cacheValue:
this deny to use cache in a web service where you need to write to a file!!!

It seems to be a bug since this behaviour is a nonsense!
Thanks,
Luigi.
Jun 14 '07 #1
5 2997

"BLUE" <bluewrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>I insert a string in cache in a property set and I retrieve that string in
the get.

I retrieve my string with Read web method and I insert it with Write web
method: to try cache I do Read, Write, Read.

When I do the second Read, string is null if in the property set,
before/after inserting data into cache I write this code:

using (StreamWriter streamWriter = new
StreamWriter(@" D:\Log.txt"))
{
streamWriter.Wr ite(cacheValue) ;
streamWriter.Fl ush();
}

Debuggin the Write, in the watch windows I see the correct just inserted
value of cache.

The same behaviour persists if I write "Hello world" instead of
cacheValue: this deny to use cache in a web service where you need to
write to a file!!!

It seems to be a bug since this behaviour is a nonsense!
Again, you should post to a dotnet.webservi ce NG that deals with Web service
issues, using VB, C# and C++ .NET. They have most likely been down the path
you're trying to go down.

Jun 14 '07 #2
On Jun 14, 11:10 am, "BLUE" <bluewrote:

<snip>
The same behaviour persists if I write "Hello world" instead of cacheValue:
this deny to use cache in a web service where you need to write to a file!!!

It seems to be a bug since this behaviour is a nonsense!
This all sounds very unlikely. Could you post a short but complete
program which demonstrates the behaviour? See http://pobox.com/~skeet/csharp/complete.html
for what I mean by that.

Jon

Jun 14 '07 #3
Finally I've found the error: if I try to write a file to bin dir (my desire
was to put all there to be tidy) the cache does not retain the values.

This is the code I used.

<%@ WebService Language="C#" Class="WS.MyWS" %>

using System;
using System.IO;
using System.Web.Serv ices;
using System.Xml;

namespace WS
{
[WebService(Name space="http://microsoft.com/webservices/")]
[WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
public class MyWS: WebService
{
private DateTime LastUpdateDateT ime
{
get
{
string path = this.Server.Map Path("bin\\File .txt");
DateTime utcNow = DateTime.UtcNow ;
DateTime lastUpdateDateT ime;
string cacheValue =
(string)this.Co ntext.Cache["lastUpdateDate Time"];
if (cacheValue != null)
return XmlConvert.ToDa teTime(cacheVal ue,
XmlDateTimeSeri alizationMode.U tc);

StreamReader streamReader = null;
try
{
streamReader = new StreamReader(pa th);
string s = streamReader.Re adToEnd().Trim( );
// I want to see if cache value is taken so I comment
the following line
// lastUpdateDateT ime = XmlConvert.ToDa teTime(s,
XmlDateTimeSeri alizationMode.U tc);
lastUpdateDateT ime = utcNow.AddYears (-7);
}
catch
{
File.Delete(pat h);
lastUpdateDateT ime = utcNow.AddYears (-7);
}
finally
{
if (streamReader != null)
streamReader.Cl ose();
}

return lastUpdateDateT ime;
}
set
{
try
{
string cacheValue = XmlConvert.ToSt ring(value,
XmlDateTimeSeri alizationMode.U tc);
this.Context.Ca che["lastUpdateDate Time"] = cacheValue;

string path = this.Server.Map Path("bin\\File .txt");
using (StreamWriter streamWriter = new
StreamWriter(pa th))
{
streamWriter.Wr ite(cacheValue) ;
streamWriter.Fl ush();
}
}
catch
{
}
}
}

[WebMethod]
public string Read()
{
DateTime dt = this.LastUpdate DateTime;
return XmlConvert.ToSt ring(dt,
XmlDateTimeSeri alizationMode.U tc);
}

[WebMethod]
public void Write()
{
this.LastUpdate DateTime = DateTime.UtcNow ;
}
}
}
Jun 14 '07 #4
On Jun 14, 2:43 pm, "BLUE" <bluewrote:
Finally I've found the error: if I try to write a file to bin dir (my desire
was to put all there to be tidy) the cache does not retain the values.
Right. I suspect ASP.NET thinks it's a change to your application, and
is recycling it (restarting the web app, basically).

Writing to the bin directory sounds like a bad idea anyway though.

Jon

Jun 14 '07 #5

"BLUE" <bluewrote in message news:u5******** ******@TK2MSFTN GP04.phx.gbl...
Finally I've found the error: if I try to write a file to bin dir (my
desire was to put all there to be tidy) the cache does not retain the
values.
One shouldn't write to the Bin directory or to wwwroot/appvirtual. It's a
security risk that a hacker can exploit. One reads a Web.config, App.config
or even a text.fle that has pathing pointing somewhere instead of anywhere
but the Web server itself on wwwroot.

Jun 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1730
by: noah | last post by:
Hi, I'm in the middle of writing a multi-user system with very critical timing issues. I've already implemented a cache and an API to access it (with appropriate locking for multithreaded access). This shared cache is critical / the primary function of the system. At the core of this system there is a cache of objects that can be modified...
4
20541
by: rex64 | last post by:
I am getting an error message and I have not been able to figure hot how to fix it. I have done some research with no answers yet. I found this code that may help? Not sure what to do with it. using (StreamWriter sw = new StreamWriter (fullAddress , false, Encoding.UTF7)) Error message::::::::::::::::::::::::::::::::::::::::::::::
10
4617
by: Oscar Thornell | last post by:
Hi, I generate and temporary saves a text file to disk. Later I upload this file to Microsoft MapPoint (not so important). The file needs to be in UTF-8 encoding and I explicitly use the "Encoding.UTF8" in the constructor like this: StreamWriter writer = new StreamWriter(file, Encoding.UTF8); When I do this the StreamWriter inserts an...
0
2038
by: Kevin | last post by:
I'm writing a service in VB.NET. Reference the following code: Dim oStreamWriter As StreamWriter .... .... .... oStreamWriter = File.CreateText(TempLogFile) If Err.Number <> 0 Then EventLog.WriteEntry("LogService", "Error Creating Log File: " & _ TempLogFile & vbCrLf & _
2
1710
by: MATT | last post by:
I am trying to create a windows service. The part I am having trouble with is writing text to a log file. I am using a very basic StreamWriter function to try to test this. I have created a very basic service app to try to test this: OnStart timer1.enabled = True OnStop
3
13767
by: =?Utf-8?B?RGFuZGFuIFpoYW5n?= | last post by:
Now I have a web application, a web service and a SQL Server database. The Web application will invoke the web service, the web service invokes the SQL Server stored procedure. I let the web service run in an application pool which runs under a domain user, this domain user has permissions of accessing database and the connection to...
11
7888
by: Joseph Geretz | last post by:
I've been looking at two approaches for the maintenance of Session state for a Web Service application. One approach uses the old familiar Session object which I've used in the past for Web applications. As far as I can see, the Session approach is non-standard since Web Services are supposed to be agnostic with respect to their clients. It...
3
9185
by: BLUE | last post by:
I've created a folder named TestDir in my wwwroot and I've created the associated virtual application from IIS management snap-in. I've given full control to TestDir to: IUSR, ASPNET, Network service, Anonimous access, Everyone, Users, VS Developers I've set write access and low application protection from IIS management snap-in.
1
5766
by: MSwanston | last post by:
Hi I need some help with saving retreiving data from the cache, and how best to structure my code. FYI am working in VS2005/under .NET2 Framework. Ok, we have a series of reports that get run via a report filter screen, and whilst each report is being generated, it populates a memorystream/streamwriter. This has always been done this way but...
0
7392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5246
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3376
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1798
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.