Hi,
I am writing web service and I want to read a file only once when I
start the web service. How can I do that? Which event fires exactly
onece when we launch web service?
I am reading a xml file in the Init() so whenever the web service is
invoked, it is reading that file. This is what I want to avoid. Where
can I write the code so that the file gets read only once? Also where
should I place the dll so that it will be accessible as long as the
web service is running. 5 6159
I'm assuming that you need to read the XML file for some class that
offers up the details in that file (which is treated as read-only, from what
I can tell).
The best way to do this is to create a static constructor for the class
which utilizes the file, and then load the file in the static constructor
into a static variable (or load the information in the file into whatever
static variables you want) and then access those from your class instances.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
<sh**********@y ahoo.comwrote in message
news:11******** **************@ z9g2000hsf.goog legroups.com...
Hi,
I am writing web service and I want to read a file only once when I
start the web service. How can I do that? Which event fires exactly
onece when we launch web service?
I am reading a xml file in the Init() so whenever the web service is
invoked, it is reading that file. This is what I want to avoid. Where
can I write the code so that the file gets read only once? Also where
should I place the dll so that it will be accessible as long as the
web service is running.
Thanks for your reply.
I am reading that file in a static variable and I am checking that
static variable before reading that file again. Everything works fine
for 10 min. or so.
But if I do not invoke the web services for more than 10 min, then I
guess the garbage collector runs and static variable looses all the
values stored in it. So I read that file again. Now, reading that file
is very expensive. So I want to reduce no. of times that I am reading
the file.
Where can I write the code so that it will be run exactly once and
will be alive as long as that session is alive.
On Nov 7, 4:53 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
I'm assuming that you need to read the XML file for some class that
offers up the details in that file (which is treated as read-only, from what
I can tell).
The best way to do this is to create a static constructor for the class
which utilizes the file, and then load the file in the static constructor
into a static variable (or load the information in the file into whatever
static variables you want) and then access those from your class instances.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om
<shashwat_...@y ahoo.comwrote in message
news:11******** **************@ z9g2000hsf.goog legroups.com...
Hi,
I am writing web service and I want to read a file only once when I
start the web service. How can I do that? Which event fires exactly
onece when we launch web service?
I am reading a xml file in the Init() so whenever the web service is
invoked, it is reading that file. This is what I want to avoid. Where
can I write the code so that the file gets read only once? Also where
should I place the dll so that it will be accessible as long as the
web service is running.- Hide quoted text -
- Show quoted text -
Try to log Application_OnE nd event in your Global.asax.
I have a asp.net server that is run on a shared hosting (GoDaddy). Every now
and then their IIS unloads my application for no apparent reason. I do store
some data in static variables, and eventually they get lost. I have to back
them up in each Application_OnE nd() and restore them in each
Application_OnS tart(). But as long as your app is alive/loaded, there
shoudn't be any problem with your variables.
Again, try and see if the reason for lost data is that your app gets
unloaded (log every Application_OnE nd). If that's the case, you need to come
up with some other ways of storing your data. Database vs File would be
another option.
<sh**********@y ahoo.comwrote in message
news:11******** *************@z 9g2000hsf.googl egroups.com...
Thanks for your reply.
I am reading that file in a static variable and I am checking that
static variable before reading that file again. Everything works fine
for 10 min. or so.
But if I do not invoke the web services for more than 10 min, then I
guess the garbage collector runs and static variable looses all the
values stored in it. So I read that file again. Now, reading that file
is very expensive. So I want to reduce no. of times that I am reading
the file.
Where can I write the code so that it will be run exactly once and
will be alive as long as that session is alive.
On Nov 7, 4:53 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
> I'm assuming that you need to read the XML file for some class that offers up the details in that file (which is treated as read-only, from what I can tell).
The best way to do this is to create a static constructor for the class which utilizes the file, and then load the file in the static constructor into a static variable (or load the information in the file into whatever static variables you want) and then access those from your class instances.
-- - Nicholas Paldino [.NET/C# MVP] - m...@spam.guard .caspershouse.c om
<shashwat_...@ yahoo.comwrote in message
news:11******* *************** @z9g2000hsf.goo glegroups.com.. .
Hi,
I am writing web service and I want to read a file only once when I
start the web service. How can I do that? Which event fires exactly
onece when we launch web service?
I am reading a xml file in the Init() so whenever the web service is
invoked, it is reading that file. This is what I want to avoid. Where
can I write the code so that the file gets read only once? Also where
should I place the dll so that it will be accessible as long as the
web service is running.- Hide quoted text -
- Show quoted text -
If you have items that you need read when the application starts, why not use
web.config? You have the appSettings section as well as custom sections. And
you
can access your data via the ConfigurationMa nager class. So, no need to
reinvent the wheel.
-- Peter http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"sh**********@y ahoo.com" wrote:
Hi,
I am writing web service and I want to read a file only once when I
start the web service. How can I do that? Which event fires exactly
onece when we launch web service?
I am reading a xml file in the Init() so whenever the web service is
invoked, it is reading that file. This is what I want to avoid. Where
can I write the code so that the file gets read only once? Also where
should I place the dll so that it will be accessible as long as the
web service is running.
In the Start method of the Service class, simply read the file and
then start the thread that does the work (you have to thread the main
code in the service or your service will never get out of start mode.
private System.Timers.T imer timer;
public MyService()
{
// InitializeCompo nents();
timer = new Timer(/* parameters for time interval */);
timer.Elapsed += // method handler with method for executing main
service code
}
// Changes status to running in service window while executing every
interval
public override void Start()
{
// Read file here
timer.Enabled = true;
}
// Changes status to stop in service window
public override void Stop()
{
// timer.Enabled = false;
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dinesh Eswaran |
last post by:
Hi,
I need to make sure that my windows service (written using C#/.NET
classes) starts up *AFTER* IIS.
How can I go about doing this?
Thanks
Dinesh
|
by: cs |
last post by:
I noticed there is some .net services on my winxp. One or two mention the
CLR. Does that mean that my .net apps/services wont run before those
services start?
I need to run my service as early on as possible, it doesnt even need to be
a service if there is a way to run .net apps before that, anyone knows what
or where?
|
by: Ken Allen |
last post by:
I have a number of services developed in C# (.Net), and they have been
working fine for the most part. Recently someone reported that ipon
occassion (originally rarely, but more frequently on some systems of
late), there is an entry in the Event Log immediately after a boot
indicating that the service failed to start after 30,000 milliseconds.
Usually it starts fine when attempting manually after the boot.
I instrumented the code to...
|
by: Anup |
last post by:
Hi All,
I have a web services(like Map point 2004) which has to be manually started
on rebooting.
Can a windows based Service(c#) be created which automatically starts a web
service.?
If so how can it be done.
Plz do reply,
anup kamat
|
by: sdstraub |
last post by:
I have created 5 services in my project, in the 1st service I set
servicestorun = array of all 5 services, I have a project installer
with 5 service installers, one for each service. I have code so that
whenever any service starts, stops or timers elapse a log entry is
created. When I install my project, and start the 1st service in the
services console, it shows that the service started and I have the
corresponding log entry confirming...
| |
by: Kürþat |
last post by:
Hi all,
I want to host a remote object in a windows service. This remote object
fires events about service state. Clients connect and consume this events.
The service configures and marshal remote object in its constructor. When a
client application starts it connects remote object, registers events and
monitors service state. So far so good. When service stops, it fires stop
event via remote object and all clients know the service was...
|
by: Sourcerer |
last post by:
I've started my first practice windows service project in C#, and I'm already
stuck.
Let's say I'm trying to make a simple service (and useless, but good for
practice). It is supposed to listen on port which is stored in its configuration
file (say C:\MyService\Config.CFG). After it receives something (anything), then
it is supposed to open a file C:\MyService\File.TXT, read the number that is
written in it, increase it by 1, save it,...
|
by: lucius |
last post by:
I need to know from within my ASP.NET 2.0 Web Service, when the
application was started as a DateTime. The service might run on
Windows Server 2000, maybe 2003, maybe 2003 R2, maybe XP (in
development on my desktop), so it might run inside an App Pool, or it
might just be a virtual directory.
How can I get this information?
Thanks.
|
by: Cramer |
last post by:
Using ASP.NET 3.5: Can a custom HTTP Module be used to register for the
Application_Start event? Or _must_ I use Global.asax to work with
Application.Start?
I understand that I can use a custom HTTP Module to register for other
pipeline events (like Application.BeginRequest), but I was told that the
only place that I can set up an event handler for Application.Start is in
Global.asax.
My preference would be to register an HTTP Module...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |