473,789 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Single Instance web service??

Is there such a thing as a single instance web service? Is it possible to
have all calls to a web service share one property value by declaring it as
static? I know web service should be stateless, but I am still trying to
understand how instances of a web service are handled at the server side, if
a unique instance is created for every call then should'nt any members
declared as "static" be shared between instances?

Any help is appreciated.
Sep 14 '07 #1
7 7738
"aesper" <ae****@discuss ions.microsoft. comwrote in message
news:2F******** *************** ***********@mic rosoft.com...
Is there such a thing as a single instance web service? Is it possible to
have all calls to a web service share one property value by declaring it
as
static? I know web service should be stateless, but I am still trying to
understand how instances of a web service are handled at the server side,
if
a unique instance is created for every call then should'nt any members
declared as "static" be shared between instances?
A single instance is created per call. Anything declared static will be
shared across all calls within the same AppDomain. More or less, that means
on the same machine and same virtual directory.

Using statics is a bad idea in general in a web service or other ASP.NET
application. This is because each request runs on a separate thread, and
more than one request can be serviced at a time. This implies that more than
one thread can be accessing your statics at the same time.

If at all possible, you should try to make the service stateless.
--
--------------------------------------------------------------------------------
John Saunders | MVP – Windows Server System – Connected System Developer

Sep 14 '07 #2
Thanks for the response.
I will make my web service stateless, but I still would like to know how
application domains are managed for a web service. Is there a way we can
ensure that there is always one application domain for the web service. I ran
a small test and it looks like there are alwasy 5 different instances of the
"static" which suggest that there are 5 different App Domains, does this
sound right?

Thanks agin for your help.

"John Saunders [MVP]" wrote:
"aesper" <ae****@discuss ions.microsoft. comwrote in message
news:2F******** *************** ***********@mic rosoft.com...
Is there such a thing as a single instance web service? Is it possible to
have all calls to a web service share one property value by declaring it
as
static? I know web service should be stateless, but I am still trying to
understand how instances of a web service are handled at the server side,
if
a unique instance is created for every call then should'nt any members
declared as "static" be shared between instances?

A single instance is created per call. Anything declared static will be
shared across all calls within the same AppDomain. More or less, that means
on the same machine and same virtual directory.

Using statics is a bad idea in general in a web service or other ASP.NET
application. This is because each request runs on a separate thread, and
more than one request can be serviced at a time. This implies that more than
one thread can be accessing your statics at the same time.

If at all possible, you should try to make the service stateless.
--
--------------------------------------------------------------------------------
John Saunders | MVP – Windows Server System – Connected System Developer

Sep 14 '07 #3
"aesper" <ae****@discuss ions.microsoft. comwrote in message
news:3F******** *************** ***********@mic rosoft.com...
Thanks for the response.
I will make my web service stateless, but I still would like to know how
application domains are managed for a web service. Is there a way we can
ensure that there is always one application domain for the web service. I
ran
a small test and it looks like there are alwasy 5 different instances of
the
"static" which suggest that there are 5 different App Domains, does this
sound right?
No, it doesn't sound right. How did you determine the number of instances of
the static?

The following applies to any ASP.NET application, including an ASP.NET web
service:

The first time a request comes in for the virtual directory, ASP.NET will
see that it does not have an instance of the application running. It will
start such an instance in a new AppDomain. This AppDomain will continue to
exist, containing each instance of the web service, until it "resets". This
can be caused by several actions, including changing files in the bin
folder, or changing the web.config. There are others as well.

Basically, you don't have to worry much about it if you don't use statics,
and don't assume that Application or Session state will always be there. The
latter two could be empty if the AppDomain shut down and you are now running
in a new AppDomain.
--
--------------------------------------------------------------------------------
John Saunders | MVP – Windows Server System – Connected System Developer

Sep 14 '07 #4
Basically what I did is generate a Guid every time the static memebr is
instantiated:

public class Counter
{
private int _value = 0;
private Guid _guid;

public Counter()
{
_value = 0;
_guid = Guid.NewGuid();
}

public string GetNextCounter( )
{
_value++;
return _guid.ToString( ) + " " + _value.ToString ();
}
}
Then my web service part looks like this:

[WebService(Name space = "http://MyCompany.WebSe rvices/")]
[WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
public class TestCounterServ ice : System.Web.Serv ices.WebService
{
#region Private Memebers
private static Counter _counter = null;
private static readonly object _lockObject = new object();
#endregion

#region Constructor
public TestCounterServ ice()
{
}
#endregion

[WebMethod]
public string GetNextCounter( )
{
string result = string.Empty;
lock (_lockObject)
{
if (_counter == null)
_counter = new Counter();

result = _counter.GetNex tCounter();
}

return result;
}

}

When I call the [WebMethod] from different clients I get the Guid which
should correspond to the Counter instance and its corresponding counter, I
launch many instances of the client application and the Guids can always be
grouped in groups of five unique Guids......

Thanks again for all your help!
"John Saunders [MVP]" wrote:
"aesper" <ae****@discuss ions.microsoft. comwrote in message
news:3F******** *************** ***********@mic rosoft.com...
Thanks for the response.
I will make my web service stateless, but I still would like to know how
application domains are managed for a web service. Is there a way we can
ensure that there is always one application domain for the web service. I
ran
a small test and it looks like there are alwasy 5 different instances of
the
"static" which suggest that there are 5 different App Domains, does this
sound right?

No, it doesn't sound right. How did you determine the number of instances of
the static?

The following applies to any ASP.NET application, including an ASP.NET web
service:

The first time a request comes in for the virtual directory, ASP.NET will
see that it does not have an instance of the application running. It will
start such an instance in a new AppDomain. This AppDomain will continue to
exist, containing each instance of the web service, until it "resets". This
can be caused by several actions, including changing files in the bin
folder, or changing the web.config. There are others as well.

Basically, you don't have to worry much about it if you don't use statics,
and don't assume that Application or Session state will always be there. The
latter two could be empty if the AppDomain shut down and you are now running
in a new AppDomain.
--
--------------------------------------------------------------------------------
John Saunders | MVP – Windows Server System – Connected System Developer

Sep 14 '07 #5
"aesper" <ae****@discuss ions.microsoft. comwrote in message
news:F9******** *************** ***********@mic rosoft.com...
Basically what I did is generate a Guid every time the static memebr is
instantiated:
....
When I call the [WebMethod] from different clients I get the Guid which
should correspond to the Counter instance and its corresponding counter, I
launch many instances of the client application and the Guids can always
be
grouped in groups of five unique Guids......
Were there five instances of the client application?

You also might consider saving DateTime.Today in a static when instantiated,
and displaying that in the web service response as well.

--
--------------------------------------------------------------------------------
John Saunders | MVP – Windows Server System – Connected System Developer

Sep 15 '07 #6
No, actually there were many more intances of the client application, I
basically have a button and an edit box. When the button is clicked the web
service is called and the result is displayed in the text box. I just keep
hitting the buttons on all instances and I always have 5 unique Guids no
matter how many client instances are running, I tried up to 100 instances.

I will try to display the time stamp and see if the results are consistent
with what I am concluding.

Thanks agin.

"John Saunders [MVP]" wrote:
"aesper" <ae****@discuss ions.microsoft. comwrote in message
news:F9******** *************** ***********@mic rosoft.com...
Basically what I did is generate a Guid every time the static memebr is
instantiated:
....
When I call the [WebMethod] from different clients I get the Guid which
should correspond to the Counter instance and its corresponding counter, I
launch many instances of the client application and the Guids can always
be
grouped in groups of five unique Guids......

Were there five instances of the client application?

You also might consider saving DateTime.Today in a static when instantiated,
and displaying that in the web service response as well.

--
--------------------------------------------------------------------------------
John Saunders | MVP – Windows Server System – Connected System Developer

Sep 15 '07 #7
I added the DateTime.Now.To String() to the web service output to indicate
when the static was instantiated. The result is the same: There are always 5
unique time stamp/Guid combinations when several instances of a client are
run. I am just wondering if there is a way to control how many app domains
are created for the web service.

"aesper" wrote:
No, actually there were many more intances of the client application, I
basically have a button and an edit box. When the button is clicked the web
service is called and the result is displayed in the text box. I just keep
hitting the buttons on all instances and I always have 5 unique Guids no
matter how many client instances are running, I tried up to 100 instances.

I will try to display the time stamp and see if the results are consistent
with what I am concluding.

Thanks agin.

"John Saunders [MVP]" wrote:
"aesper" <ae****@discuss ions.microsoft. comwrote in message
news:F9******** *************** ***********@mic rosoft.com...
Basically what I did is generate a Guid every time the static memebr is
instantiated:
....
When I call the [WebMethod] from different clients I get the Guid which
should correspond to the Counter instance and its corresponding counter, I
launch many instances of the client application and the Guids can always
be
grouped in groups of five unique Guids......
Were there five instances of the client application?

You also might consider saving DateTime.Today in a static when instantiated,
and displaying that in the web service response as well.

--
--------------------------------------------------------------------------------
John Saunders | MVP – Windows Server System – Connected System Developer
Sep 17 '07 #8

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

Similar topics

2
8005
by: meng | last post by:
is it possible to use a single connection object shared by several tasks where each task is handled by a thread? these tasks call stored procedures that return record sets, no editing, update or delete. my objective is that db connection is expensive and each user can only have 1 connection object. each user submits a request to the web server, and the result web page construction consists of a number of result sets obtained from several...
3
1621
by: Prabhu Shastry | last post by:
Hello group, I have a Windows Service and an application (C#). Both processes need access to a single dataset object (created and modified by the service and application will only read the dataset). I thought this was possible with ..Net remoting, but not able to figure out a way to make this possible. Does anyone know if it's possible to achieve this? Thanks, -Prabhu
4
4210
by: Jason | last post by:
I have a web service running on IIS 5.0. We know the web service is not threadsafe, and want to force aspnet_wp.exe to only run one instance of our web service. What settings do we use to do this. I have tried modifying the machine.config file and setting maxWorkerThreads=1. However, then I can't even get aspnet_wp.exe to load. Can anyone help me out here?
4
1466
by: Sniper | last post by:
Hi guys I have facing a small problem, it's like this. There is a web service which has a web method call OpenPublicConnection which will open a connection to the SQL Server, and there is a web method call StartTransaction to start a tranaction for the class level connection which is opened by the OpenPublicConection Method. But when I call StartTransaction it's retruing an error saing the connection is closed... ? Is there anyway...
6
4964
by: ben | last post by:
I am needing a web service to be single threaded. Is this possible? Any ideas would be helpful
9
5113
by: MrSpock | last post by:
1. Create a new Windows Application project. 2. Open the project properties and check "Make single instance application". 3. Build. 4. Go to the release folder and run the application. 5. Try to open a second instance of the application. This will cause an unhandled exception and the "Send Error Report" box shows up. Does this happen to anyone else, or is it just me? Debug info: "Unhandled exception at 0x00e149fd in...
6
2271
by: kumar_anil_gaya_India | last post by:
Hi All, I am facing one problem. I have one DLL called LogManagement which has ability to write to ExceptionLog and EventLog File. Both are separate file locate in Logs Diectory. I have two windows service application and one windows application which call the LogManagement DLL to write to log file. I made the object of LogManagement as Singleton but when I run single application, It runs perfect, but when I run
0
1759
by: sandrofurlan | last post by:
Hi all, i have a WCF service for USB communication. I need to instance it as a singleton class so i do: <ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single, _ ConcurrencyMode:=ConcurrencyMode.Multiple)_ Public Class myService ....
3
1720
by: sklett | last post by:
I suspect the answer might be in one of the words of my subject, but here goes anyway. I'm working on a system that will execute a very long (300+) chain of task objects. Here is some quick pseudo code to illustrate: public class VideoAcquisition { public Image GetFrame(){}; // other stuff
0
9511
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
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,...
0
9020
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
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
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.