473,411 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Member variables in Web Service class

Hi, if I have the following class:

[WebService(Namespace = "http://www.softease.com/Podium")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MyWebService : System.Web.Services.WebService
{
private String m_name;

[WebMethod]
public String SayHello(String name)
{
m_name = name;
return "Hello " + m_name;
}

[WebMethod]
public String SayGoodbye()
{
return "Goodbye " + m_name;
}
}

That won't work will it? Because WebService's are stateless? Even though
I keep an instance of the web service on my client.

So how can I store information, such as a username? I know I can use the
Session object, but I was lead to believe that it isn't best to use the
Session object in web services??
Any help is much appreciated.

Cheers,
Oct 27 '06 #1
5 5148
hejdig.

The buzz word of today is "stateless". So most people don't want states in
their web services.

Another thing is that web services are slower than "ordinary calls" and
statefull object tend to be more "chatty". So if you have a web service
with a state you might be tempted to use it as an ordinary business object
with lots of calls and that might affect performance.

Otherwise there is nothing wrong with haveing states in you web services.

HTH

/OF

----
>"Mark Ingram" <no****@nowhere.comwrote in message
news:e6****************@TK2MSFTNGP04.phx.gbl...
Hi, if I have the following class:
[WebService(Namespace = "http://www.softease.com/Podium")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MyWebService : System.Web.Services.WebService
{
private String m_name;
[WebMethod]
public String SayHello(String name)
{
m_name = name;
return "Hello " + m_name;
}
[WebMethod]
public String SayGoodbye()
{
return "Goodbye " + m_name;
}
}
That won't work will it? Because WebService's are stateless? Even though I
keep an instance of the web service on my client.
So how can I store information, such as a username? I know I can use the
Session object, but I was lead to believe that it isn't best to use the
Session object in web services??

Oct 27 '06 #2
LosManos wrote:
hejdig.

The buzz word of today is "stateless". So most people don't want states in
their web services.
I'm not concerned with using states, I need them in this instance (I am
writing a file upload web service, with functions for starting the
transfer, appending chunks of data and finishing the transfer). I am
more concerned with the usage of the HttpSessionState and the impact it
will have on the speed of the web service. From what i've read it should
be avoided?
Oct 27 '06 #3
Hi,

Mark Ingram wrote:
Hi, if I have the following class:

[WebService(Namespace = "http://www.softease.com/Podium")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MyWebService : System.Web.Services.WebService
{
private String m_name;

[WebMethod]
public String SayHello(String name)
{
m_name = name;
return "Hello " + m_name;
}

[WebMethod]
public String SayGoodbye()
{
return "Goodbye " + m_name;
}
}

That won't work will it? Because WebService's are stateless? Even though
I keep an instance of the web service on my client.

So how can I store information, such as a username? I know I can use the
Session object, but I was lead to believe that it isn't best to use the
Session object in web services??
Any help is much appreciated.

Cheers,
You are correct, it's exactly like with Pages (ASPX files with code
behind), a new instance is created on every Request. Member variables
will be discarded together with the whole class when the Response has
been sent.

You are also correct that you can access the Session object in web
services, but you must mark the web method with
[WebMethod( enableSession=true )]

Otherwise, the session will not be enabled.

Also, make sure that the Global.asax file is present in your project, or
else the session management is not done correctly. In ASP.NET 1.1,
Global.asax was added per default to each new web app (web service or
web site). In ASP.NET 2.0, it's not anymore, but you can add one manually.

See
http://geekswithblogs.net/lbugnion/a.../11/93737.aspx

In a page (ASPX), you can also use the enablesessionstate in the Page
directive, but I am not sure if you can also do this in a web service.
Adding the Global.asax should be a better choice in that case.

There is nothing wrong with using Session in web services, as long as
you are aware of the cost (performance, memory, etc...). In fact, more
and more I tend to believe that making a stateless web application (as
opposed to a website) is almost not possible. Stateless web sites, in
the contrary, are not a problem.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 27 '06 #4
Laurent Bugnion wrote:
See
http://geekswithblogs.net/lbugnion/a.../11/93737.aspx
There is nothing wrong with using Session in web services, as long as
you are aware of the cost (performance, memory, etc...). In fact, more
and more I tend to believe that making a stateless web application (as
opposed to a website) is almost not possible. Stateless web sites, in
the contrary, are not a problem.

Greetings,
Laurent
Thanks Laurent.

Is there a ratio that defines *how* much slower a web service will run
with sessions enabled? I can't imagine it would make too much of a
difference
Nov 3 '06 #5
Hi,

Mark Ingram wrote:
Laurent Bugnion wrote:
>See
http://geekswithblogs.net/lbugnion/a.../11/93737.aspx
>There is nothing wrong with using Session in web services, as long as
you are aware of the cost (performance, memory, etc...). In fact, more
and more I tend to believe that making a stateless web application (as
opposed to a website) is almost not possible. Stateless web sites, in
the contrary, are not a problem.

Greetings,
Laurent

Thanks Laurent.

Is there a ratio that defines *how* much slower a web service will run
with sessions enabled? I can't imagine it would make too much of a
difference
Never heard of that ;-) Anyway as you can imagine, it will depend much
on the nature of the saved objects, on the frequency with which they
will be accessed, etc... Besides, there are many other places on the
line which will affect the speed with which the page is rendered.

As a rule of thumb, I would keep that in mind, and start by choosing the
easy way (using the session) but with a layering such that you can
easily choose another way to persist your objects if speed becomes an issue.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 3 '06 #6

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

Similar topics

11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
3
by: prabhu | last post by:
hello to all, Please can anybody tell me the differnece between static and ordinary member variables. thankyou in advance, vishnu
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
1
by: mangalalei | last post by:
A static data member can be of the same class type as that of which it is a member. A nonstatic data member is restricted to being declared as a pointer or a reference to an object of its class. ...
7
by: Valeriu Catina | last post by:
Hi, consider the Shape class from the FAQ: class Shape{ public: Shape(); virtual ~Shape(); virtual void draw() = 0;
15
by: Bob Johnson | last post by:
I have a base class that must have a member variable populated by, and only by, derived classes. It appears that if I declare the variable as "internal protected" then the base class *can*...
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
13
by: Henri.Chinasque | last post by:
Hi all, I am wondering about thread safety and member variables. If I have such a class: class foo { private float m_floater = 0.0; public void bar(){ m_floater = true; }
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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,...
0
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...

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.