473,320 Members | 2,048 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,320 software developers and data experts.

how to keep login state in web service

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
bLogin. When the login is sucessful I set the bool to true.

But when I tested my webservice from my testing program (a
console application), I call login method first, I stepped
through all steps and I knew the blogin had been set to be
true. Then from my testing program I called another web
method by using the same instance of the webservice, the
wired thing happened: the bLogin flag was reset back to
false.

Any idea?

Thanks a lot.

Linda Chen
Nov 21 '05 #1
1 3948
Linda, web services are stateless by design, meaning that every call you
make will "forget" about any previous call. There are ways around this. If
you want to remember your login variable, you can do the following:

In your login method, create a session variable called "bLogin". You can do
this by saying Session("bLogin") = "true". (Assuming you are using VB. C#
use Session["bLogin"] = true). In all of your web methods, put an
attribute in front of them to make them session aware, and you can then
check bLogin to see if it is true or false. It will remember the value.
VB:

<System.Web.Services.WebMethod(EnableSession:=True )> _
Public Function DoSomething() As Integer
if CType(Session("bLogin"), Boolean) = true then

Return 1
else
Return 2
end if
End Function

C#:
[System.Web.Services.WebMethod(EnableSession=true)]
public int DoSomething()
{
if ((bool) Session["bLogin"] == true)
{
return(1);
}
else
{
return(2);
}

}

"Linda Chen" <li********@faa.gov> wrote in message
news:20*****************************@phx.gbl...
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
bLogin. When the login is sucessful I set the bool to true.

But when I tested my webservice from my testing program (a
console application), I call login method first, I stepped
through all steps and I knew the blogin had been set to be
true. Then from my testing program I called another web
method by using the same instance of the webservice, the
wired thing happened: the bLogin flag was reset back to
false.

Any idea?

Thanks a lot.

Linda Chen

Nov 21 '05 #2

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

Similar topics

3
by: Zachary Burns | last post by:
I'm trying to scrape a page that requires me to login to it. I'm not sure if it uses cookies or not to track if I'm logged in, could it be using viewstate? Anyway, can I do this using the...
3
by: Paul | last post by:
Hello, First I want to refer to the problem "WebRequest : execute a button" of a few days ago. The way I solved it, I loose my session, and as a consequence my session variables. I don't want...
2
by: pvl | last post by:
Hi We have the following scenario: 1. SQL server 2000 on Windows 2003 Server 2. Web server 1, running web service 1 on Windows 2003 Server 3. Web server 2, running web service 2 on Windows 2000...
10
by: et | last post by:
I have an asp.net program that uses a connection string, using integrated security to connect to a sql database. It runs fine on one server, but the other server gives me the error that "Login...
10
by: BLUE | last post by:
I'm using SQL Server 2005 Developer Edition on Windows XP SP2 with this setting: <add name="SqlServerTrustedConn" providerName="System.Data.SqlClient" connectionString="Data...
0
by: Jean | last post by:
Hi, I have a question about logins and sql server express and an ASP.NET aplication. I put this question in sql server newsgroup, but without real answer sofar. I created a login 'Network...
3
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
4
by: Brett | last post by:
I have an ASP.NET 2.0 application that uses Forms Authentication. The startup page contains just a login control, and the site works well on an IIS 6 web server. I am now setting the site up on...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app. When session is invalid, how to redirect user to the login page? I don't want to add the code to redirect user to the login page into every page. Thanks, -Billy
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.