473,395 Members | 1,496 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,395 software developers and data experts.

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

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
Nov 23 '05 #1
7 1999
> 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" <al********@mio.it> wrote in message
news:66********************@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

Nov 23 '05 #2
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" <al********@mio.it> wrote in message
news:66********************@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


Nov 23 '05 #3
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" <al********@mio.it> wrote in message
news:81********************@news.tin.it...
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" <al********@mio.it> wrote in message
news:66********************@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


Nov 23 '05 #4
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" <al********@mio.it> wrote in message
news:81********************@news.tin.it...
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" <al********@mio.it> wrote in message
news:66********************@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



Nov 23 '05 #5
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" <al********@mio.it> wrote in message
news:66********************@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

Nov 23 '05 #6
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
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" <al********@mio.it> wrote in message
news:66********************@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


Nov 23 '05 #7
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" <al********@mio.it> wrote in message
news:85********************@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
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" <al********@mio.it> wrote in message
news:66********************@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


Nov 23 '05 #8

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

Similar topics

1
by: Jonathan | last post by:
Hello, I'm writed a WebCustomControl but I can't mantain the viewstate this is the code of my WebCustomContol: public class WebCustomControl1 : System.Web.UI.WebControls.WebControl,...
0
by: cdani | last post by:
Hello. I have an applicattion with visual basic.net, which uses windows forms. How can I mantain a session in different calls to the same webservice? (which uses some database access). The goal...
1
by: Linda Chen | last post by:
Hello, I made a webservice, the user is asked to login to the server before making other calls. I have problem to keep the login state. Inside my web service I have a private boolean called...
4
by: Tim Gallivan | last post by:
Hello group, I'm trying to develop a proof of concept webservice which asynchronously calls a function in a DLL. The function raises an event when it is finished, and works when used as part of...
2
by: Riga | last post by:
Hi guys, I'm making a webservice that will be used by a pocketpc app. I want to be able to keep an instance of some things (there are 2 collections and possibly a database connection). Is there...
1
by: A.M-SG | last post by:
Hi, I have a web service with two soap extensions enabled on it. When I run the default IIS method invoke page, the invoke button bypasses all my soap extensions. But when I call the...
5
by: joeblast | last post by:
I have a Web service that gets the financial periods and hold a reference to a disconnected dataset built at initialization. Web methods work on the dataset inside the web service. Everything is...
2
by: Zeba | last post by:
Hi guys! I'm new to JS / Ajax; I've been trying to do an Ajax call to my Webservice ( I'm using C# for code-behind). I'm not using any of the libraries available. I am sending my CustID to the...
3
by: James | last post by:
Hi, I have built a windows app that makes calls to a webservice. Both webservice and windows apps are built with .net 2.0. The problem is... when I run the client Windows app on the dev machine,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.