473,224 Members | 1,504 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,224 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 1993
> 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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.