Is Web Service stateless ?

B

Bsiang Tan

Dear all experts,

Here is my web service code :

......
private int Number = -1;
.......
[WebMethod]
public void InitNumber(int num)
{
.....
this.Number = num;
}

[WebMethod]
public int GetNumber( )
{
.....
return Number;
}


in my web app code :

{
TestService Service = new TestService( );
....
....
// Invoke Web Service InitNumber method
Service.InitNumber( 100 );

....
....
int i = Service.GetNumber( );
....
....
}

What I get from variable i is -1, although I call the InitNumber( ) and set
it to 100.
Is it web service a stateless ?
Is it mean that each time I call the Web Service, it actually re-instantiate
?

Thank for you all helpful hands...


Best regards,
Bsiang
 
J

Joe H

if you are calling it over HTTP/S...i don't see how it could be otherwise.
that is the nature of HTTP/S. i am sure you could find ways to persist
session information and persist data across calls. but that would not be a
default behavior.
 
J

Jan Tielens

To maintain session state:
WebMethodAttribute.EnableSession Property
Indicates whether session state is enabled for an XML Web service method.
http://tinyurl.com/2rs6d
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


Joe H said:
if you are calling it over HTTP/S...i don't see how it could be otherwise.
that is the nature of HTTP/S. i am sure you could find ways to persist
session information and persist data across calls. but that would not be a
default behavior.

Bsiang Tan said:
Dear all experts,

Here is my web service code :

......
private int Number = -1;
.......
[WebMethod]
public void InitNumber(int num)
{
.....
this.Number = num;
}

[WebMethod]
public int GetNumber( )
{
.....
return Number;
}


in my web app code :

{
TestService Service = new TestService( );
....
....
// Invoke Web Service InitNumber method
Service.InitNumber( 100 );

....
....
int i = Service.GetNumber( );
....
....
}

What I get from variable i is -1, although I call the InitNumber( ) and set
it to 100.
Is it web service a stateless ?
Is it mean that each time I call the Web Service, it actually re-instantiate
?

Thank for you all helpful hands...


Best regards,
Bsiang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top