Home > Archive > Microsoft Webservices > March 2005 > How to mantain the state between 2 call of the same WebService?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to mantain the state between 2 call of the same WebService?
|
|
| Alessandro Benedetti 2005-03-17, 8:59 am |
| Hi. I'm calling two methods of a .NET Webservice (A) from another Webservice
(B).
The A Webservice is made like this:
[WebService(Namespace="WebServiceA")]
public class WSA: System.Web.Services.WebService
{
private int X = 0;
[WebMethod(EnableSession=true)]
public void WM1()
{
X = 1;
}
[WebMethod(EnableSession=true)]
public string WM2()
{
return(X);
}
}
In B WebService I make only one instantion of the A Webservice's proxy class
and then call first method (WM1) and then the second one (WM2) but WM2 always
return 0.
So, I've used Session to save my variable, but I would like to know if there
is another way that doesn't use session that I don't like.
Thank you.
Alessandro
| |
| Kevin Spencer 2005-03-17, 4:01 pm |
| > is another way that doesn't use session that I don't like.
You have the same intrinsic objec ts available from the HttpContext that you
have with an ASP.Net app, which includes Application, Sessin, Server, etc.
Take your pick.
I'm a bit curious, however, as to why you "don't like" Session. Kind of an
odd statment coming from a programmer. Reminds me of a carpenter saying "I'd
like to cut this plywood, but I don't like table saws, so I'll use a
circular saw instead." Table saws and Session have their place.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
What You S Is What You Get.
"Alessandro Benedetti" <alessandro@mio.it> wrote in message
news:6697632466584359160262@news.tin.it...
> Hi. I'm calling two methods of a .NET Webservice (A) from another
> Webservice (B).
>
> The A Webservice is made like this:
>
> [WebService(Namespace="WebServiceA")]
> public class WSA: System.Web.Services.WebService
> {
> private int X = 0;
> [WebMethod(EnableSession=true)]
> public void WM1()
> { X = 1;
> }
>
> [WebMethod(EnableSession=true)]
> public string WM2()
> { return(X);
> }
> }
>
> In B WebService I make only one instantion of the A Webservice's proxy
> class and then call first method (WM1) and then the second one (WM2) but
> WM2 always return 0.
> So, I've used Session to save my variable, but I would like to know if
> there is another way that doesn't use session that I don't like.
>
> Thank you.
> Alessandro
>
>
| |
| Alessandro Benedetti 2005-03-17, 4:01 pm |
| Hello Kevin,
> You have the same intrinsic objec ts available from the HttpContext
> that you have with an ASP.Net app, which includes Application, Sessin,
> Server, etc. Take your pick.
>
> I'm a bit curious, however, as to why you "don't like" Session. Kind
> of an odd statment coming from a programmer. Reminds me of a carpenter
> saying "I'd like to cut this plywood, but I don't like table saws, so
> I'll use a circular saw instead." Table saws and Session have their
> place.
>
Well, session variables are perfect for many application but they use a lot
of memory and have a session timeout. The webservice that I've to consume
have to do long operation (a lot of minutes). Since I don't know how much
time the webservice work I can't use session variables because I can't set
the correct timeout. Moreover to use sessions I have to implement System.Net.CookieContainer,
but if I want to call the Webservice from another language like Java or ASP
or PHP I don't know to do it.
So I think that I can use Table saws and I have to find my circular saw ;-)
Thank you.
Alessandro
PS: Sorry for my bad english, I'm from Italy.
[color=darkred]
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> What You S Is What You Get.
> "Alessandro Benedetti" <alessandro@mio.it> wrote in message
> news:6697632466584359160262@news.tin.it...
>
| |
| Kevin Spencer 2005-03-17, 4:01 pm |
| Hi Alessandro,
Let me tell you about a Web Service client app that we are building that use
a SWF for the front end, and a Web Service for the back end. It keeps track
of who is logged on using Session. Now, I don't know where you got the idea
that "they use a lot of memory" but that is not true. Does a variable use a
lot of memory? The answer is, it uses as much memory as you store in it.
Same thing goes for Session. Now, our app uses Session, but it doesn't store
a whole lot there. To handle the Timeout issue, we created a WebMethod
called "Ping" which simply passes the user id to the server, and keeps their
Session alive. The beauty part is, if they close their browser or navigate
away, the Session cleans everything up automaticallly when it ends. And it
ends 20 minutes after the last Request.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
What You S Is What You Get.
"Alessandro Benedetti" <alessandro@mio.it> wrote in message
news:8174632466716324306408@news.tin.it...
> Hello Kevin,
>
>
> Well, session variables are perfect for many application but they use a
> lot of memory and have a session timeout. The webservice that I've to
> consume have to do long operation (a lot of minutes). Since I don't know
> how much time the webservice work I can't use session variables because I
> can't set the correct timeout. Moreover to use sessions I have to
> implement System.Net.CookieContainer, but if I want to call the Webservice
> from another language like Java or ASP or PHP I don't know to do it.
> So I think that I can use Table saws and I have to find my circular saw
> ;-)
>
> Thank you.
>
> Alessandro
>
> PS: Sorry for my bad english, I'm from Italy.
>
>
>
>
| |
| Alessandro Benedetti 2005-03-17, 4:01 pm |
| Hello Kevin, as Brock Allen replied me, Session variable is not the correct
way. I paste his comment:
" Also, I'd beware of using things like Session, as that relies upon an out
of band contract of using cookies from the client. The web service specs
don't incorporate these like browsers do. If you do use Sessions/cookies,
then what's a java client going to do? What about a perl script client? Where
in the WSDL does it to say use cookies? If you have to explain to them outside
of your WSDL file that cookies are required on their end, then you're no
longer really doing web services... at least in the spirt of the web service
specs. You've just built your own XML protocol that sorta looks like SOAP....
"
.... moreover I have to add that Session protocol relies on text files (cookies)
and I think (but it is only my opinion) that session variables occupies more
memory because the data have to be transformed in text data (like base64
I think). Not only, as Brock wrote, if you use Session variables you have
the data in server memory and in client too (in cookie file). At least if
client doesn't accept cookies (don't ask me why some people are scared by
cookies ;-) ), he can't use the webservice.
Your solution is perfect for your example, but I have to do with a lot of
webservice request (like thousand per hour) and every request can take from
a few seconds to more than 3 hours, so I have to generate too many traffic
using a ping solution.
Thanks.
Alessandro Benedetti
[color=darkred]
> Hi Alessandro,
>
> Let me tell you about a Web Service client app that we are building
> that use a SWF for the front end, and a Web Service for the back end.
> It keeps track of who is logged on using Session. Now, I don't know
> where you got the idea that "they use a lot of memory" but that is not
> true. Does a variable use a lot of memory? The answer is, it uses as
> much memory as you store in it. Same thing goes for Session. Now, our
> app uses Session, but it doesn't store a whole lot there. To handle
> the Timeout issue, we created a WebMethod called "Ping" which simply
> passes the user id to the server, and keeps their Session alive. The
> beauty part is, if they close their browser or navigate away, the
> Session cleans everything up automaticallly when it ends. And it ends
> 20 minutes after the last Request.
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> What You S Is What You Get.
> "Alessandro Benedetti" <alessandro@mio.it> wrote in message
> news:8174632466716324306408@news.tin.it...
>
| |
| Manohar Kamath 2005-03-17, 4:01 pm |
| Allesandro,
Why not simply do a:
[WebMethod(EnableSession=true)]
public MyClass WM1()
{
//Assuming X is an object of type MyClass
return X;
}
The MyClass object will be serialized and sent across.
--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Alessandro Benedetti" <alessandro@mio.it> wrote in message
news:6697632466584359160262@news.tin.it...
> Hi. I'm calling two methods of a .NET Webservice (A) from another
Webservice
> (B).
>
> The A Webservice is made like this:
>
> [WebService(Namespace="WebServiceA")]
> public class WSA: System.Web.Services.WebService
> {
> private int X = 0;
>
> [WebMethod(EnableSession=true)]
> public void WM1()
> {
> X = 1;
> }
>
> [WebMethod(EnableSession=true)]
> public string WM2()
> {
> return(X);
> }
> }
>
> In B WebService I make only one instantion of the A Webservice's proxy
class
> and then call first method (WM1) and then the second one (WM2) but WM2
always
> return 0.
> So, I've used Session to save my variable, but I would like to know if
there
> is another way that doesn't use session that I don't like.
>
> Thank you.
> Alessandro
>
>
| |
| Alessandro Benedetti 2005-03-17, 4:01 pm |
| Hello Manohar, yours is the same solution as Brock Allen i think. I didn't
know that it is possibile to do that with any type of object. I will try
(and I'll read documentation about serialization because I don't know nothing
about it).
My question is, if the client is a Java application for example, the app
have to save the result in a generic object?
Thank you
Alessandro Benedetti
[color=darkred]
> Allesandro,
>
> Why not simply do a:
>
> [WebMethod(EnableSession=true)]
> public MyClass WM1()
> {
> //Assuming X is an object of type MyClass
> return X;
> }
> The MyClass object will be serialized and sent across.
>
> "Alessandro Benedetti" <alessandro@mio.it> wrote in message
> news:6697632466584359160262@news.tin.it...
>
> Webservice
>
> class
>
> always
>
> there
>
| |
| Manohar Kamath 2005-03-17, 4:01 pm |
| As long as these custom classes have fundamental types, you should be able
to build a proxy in Java, and talk to a .NET web service. Although I haven't
worked on such architectures, I am guessing types like DataSet probably
won't be as easy.
--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Alessandro Benedetti" <alessandro@mio.it> wrote in message
news:8540632466796225270821@news.tin.it...
> Hello Manohar, yours is the same solution as Brock Allen i think. I didn't
> know that it is possibile to do that with any type of object. I will try
> (and I'll read documentation about serialization because I don't know
nothing
> about it).
> My question is, if the client is a Java application for example, the app
> have to save the result in a generic object?
>
> Thank you
> Alessandro Benedetti
>
>
>
>
|
|
|
|
|