Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > How to mantain the state between 2 call of the same WebService?

Reply
Thread Tools

How to mantain the state between 2 call of the same WebService?

 
 
Alessandro Benedetti
Guest
Posts: n/a
 
      03-17-2005
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.
Alessandr


 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      03-17-2005
WebServices don't inherently support tracking the correlation of discrete
calls, as it's intended to be a disconnected messaging mechanism. So, if
you want this, you need to build in the correlation yourself. Here's an example:

// My Order Service
[WebMethod] string PlaceOrder( ... ) { ... return OrderID; }
[WebMethod] string GetOrderStatusOrder( string OrderID ) { ... }
[WebMethod] bool CancelOrder( string OrderID ) { ... }

Anyway, simple idea, but notice how the WebMethods track the user? The first
call returns an OrderID. This is now the token that identifies the user and
for all the other operations the user needs to present this information so
the web service knows who it's talking to.

The idea is the same with HTML applications. When you go to amazon.com you
need to pass some info in to "remind" the web server who you were so it can
continue whatever conversation it was having with you...

-Brock
DevelopMentor
http://staff.develop.com/ballen



> 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




 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      03-17-2005
> 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 Seek Is What You Get.

"Alessandro Benedetti" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Alessandro Benedetti
Guest
Posts: n/a
 
      03-17-2005
Hello Brock, thank you or your answer. Your solution is correct if I have
to work only with primitive type. The problem is that I have to work with
a custom class like this example:

[WebService(Namespace="WebServiceA")]
public class WSA: System.Web.Services.WebService
{

CL1 test;

public WSA()
{
this.test=new CL1;
}

[WebMethod(EnableSession=true)]
public void WM1() { test.SomeMethod(); }

[WebMethod(EnableSession=true)]
public string WM2() { return(test.SomeValue); }

}

public class CL1
{
....
}

> WebServices don't inherently support tracking the correlation of
> discrete calls, as it's intended to be a disconnected messaging
> mechanism. So, if you want this, you need to build in the correlation
> yourself. Here's an example:
>
> // My Order Service
> [WebMethod] string PlaceOrder( ... ) { ... return OrderID; }
> [WebMethod] string GetOrderStatusOrder( string OrderID ) { ... }
> [WebMethod] bool CancelOrder( string OrderID ) { ... }
> Anyway, simple idea, but notice how the WebMethods track the user? The
> first call returns an OrderID. This is now the token that identifies
> the user and for all the other operations the user needs to present
> this information so the web service knows who it's talking to.
>
> The idea is the same with HTML applications. When you go to amazon.com
> you need to pass some info in to "remind" the web server who you were
> so it can continue whatever conversation it was having with you...
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>> 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





 
Reply With Quote
 
Alessandro Benedetti
Guest
Posts: n/a
 
      03-17-2005
Hello Kevin,

>> 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.
>


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.

> Kevin Spencer
> Microsoft MVP
> .Net Developer
> What You Seek Is What You Get.
> "Alessandro Benedetti" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> 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




 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      03-17-2005
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 Seek Is What You Get.

"Alessandro Benedetti" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello Kevin,
>
>>> 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.
>>

>
> 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.
>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> What You Seek Is What You Get.
>> "Alessandro Benedetti" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>
>>> 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

>
>
>



 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      03-17-2005
> The problem is that I have to
> work with a custom class like this example:


So that's fine. I don't see what the problem is then? Every request in creates
a new instance of the WSA class. This protocol is not stateful. That's why
you're going to have to build in your own correlation mechanism as I mentioned
before. This stuff isn't easy -- don't let the VS.NET wizards fool you.

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....

-Brock
DevelopMentor
http://staff.develop.com/ballen




 
Reply With Quote
 
Alessandro Benedetti
Guest
Posts: n/a
 
      03-17-2005
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

> 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 Seek Is What You Get.
> "Alessandro Benedetti" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> Hello Kevin,
>>
>>>> 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.
>>>

>> 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.
>>
>>> Kevin Spencer
>>> Microsoft MVP
>>> .Net Developer
>>> What You Seek Is What You Get.
>>> "Alessandro Benedetti" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> 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





 
Reply With Quote
 
Alessandro Benedetti
Guest
Posts: n/a
 
      03-17-2005
Hello Brock, I don't know if I've understanding correctly your answer. You
are telling me that I can return any object from a WebService?

So in my example I can do this?

[WebService(Namespace="WebServiceA")]
public class WSA: System.Web.Services.WebService
{

[WebMethod(EnableSession=true)]
public CL1 WM1()
{
CL1 test;
test.SomeMethod();
}

[WebMethod(EnableSession=true)]
public string WM2(CL1 LocalTest)
{
return(LocalTest.SomeValue);
}

}

public class CL1
{
....
}


And if I can, how tha caller that doesn't know the object CL1 can send this
parameter?

Thank you.
Alessandro Benedetti

>> The problem is that I have to
>> work with a custom class like this example:

> So that's fine. I don't see what the problem is then? Every request in
> creates a new instance of the WSA class. This protocol is not
> stateful. That's why you're going to have to build in your own
> correlation mechanism as I mentioned before. This stuff isn't easy --
> don't let the VS.NET wizards fool you.
>
> 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....
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen





 
Reply With Quote
 
Manohar Kamath
Guest
Posts: n/a
 
      03-17-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Mantain IDE colors and paste them in an HTML page billie Python 3 10-05-2005 06:02 AM
Mantain Property Mike ASP .Net Building Controls 1 03-14-2005 03:35 PM
Mantain ViewState Jonathan ASP .Net Web Controls 0 03-10-2005 12:25 PM
Mantain ViewState Jonathan ASP .Net 1 03-09-2005 10:11 PM



Advertisments