470,641 Members | 1,575 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

Can I start a web service before anyone connects?

I am new to web services, and wonder if it is possible to have a web
service run all time and start the constructor before anyone calls any
web method. My problem is that a lot of data is read in the
constructor, and if this is to be loaded every time somebody calls a
web method, thing are really slow. I have tried to just call the web
methods, but it seems like the constructor is called every time.

May 5 '06 #1
4 1163
All you can do is make an app which will call a method (or methods) on the
web service after the service has restarted (or browse to it in IE).
Unfortunately until the first call is made the web app is not loaded and as
you say it is a bit slow the first time. Once it is loaded it will stay
loaded so performance should improve.

Will
<ma*************@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
I am new to web services, and wonder if it is possible to have a web
service run all time and start the constructor before anyone calls any
web method. My problem is that a lot of data is read in the
constructor, and if this is to be loaded every time somebody calls a
web method, thing are really slow. I have tried to just call the web
methods, but it seems like the constructor is called every time.

May 5 '06 #2
If you don't need to load the data every time - why not store the data
using statics?

You could even use the cache and inside your constructor, check to see
if the cache is empty. If it is, populate it, if it isn't use it.

Josh
http://www.thejoyofcode.com/

May 5 '06 #3
A new instance of the class is created for each request .. this helps remove
threading problems you may run into as your class does not need to be
re-entrant.

To work around this either move your initialization to another class
(singleton pattern would work very well for this) or move them into static
variable within the class so they are shared between all instances.

Cheers,

Greg Young
MVP - Visual C#

<ma*************@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
I am new to web services, and wonder if it is possible to have a web
service run all time and start the constructor before anyone calls any
web method. My problem is that a lot of data is read in the
constructor, and if this is to be loaded every time somebody calls a
web method, thing are really slow. I have tried to just call the web
methods, but it seems like the constructor is called every time.

May 5 '06 #4
Create a method, for instance InitData, which delivers as array or structure
all necessary data to run the all web service methods.
Instruct the users to write this code in Web Applications

sttruct MyData
{
string data1…;

string dataN…;
int nun1;
….
};

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
if (Application ["First"] == null)
{
MyData = InitData ();
InitAppData ()
}
Application ["First "] = 1;
}
}

private struct InitAppData ()
{
Application [“Data1”] = MyData.data1;
……..
Application [“DataN”] = MyData.dataN;
…..
}

The Application objects are available for all sessions with the same values.
Another way is to use the Application_Start event in Global.asax to load the
Application objects.

private void Application_Start (object ob, EventArgs e)
{
MyData = InitData();
InitAppData ();
}
Have a fun!

Valentin

Do not hesitate to contact me!

www.wwv-it.eu
va*************@t-online.de
"ma*************@gmail.com" wrote:
I am new to web services, and wonder if it is possible to have a web
service run all time and start the constructor before anyone calls any
web method. My problem is that a lot of data is read in the
constructor, and if this is to be loaded every time somebody calls a
web method, thing are really slow. I have tried to just call the web
methods, but it seems like the constructor is called every time.

May 10 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jack Smith | last post: by
29 posts views Thread by Ken Allen | last post: by
20 posts views Thread by Moty Michaely | last post: by
3 posts views Thread by tshad | last post: by
6 posts views Thread by uuyytt | last post: by
4 posts views Thread by cappjr | last post: by
1 post views Thread by Korara | last post: by
???
1 post views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.