WebService Client Context

P

Paul R

Hi.

I have a question about how to call a WebService from a a Windows Forms
application.

I have developed a WebService that has a Login method. Stripped down, it
looks like this….

public bool Login(string userName, string password )
{
bool bLoggedIn = false;
if( userName.Length > 0 && password.Length > 0 )
{
// bLoggedIn = do login here
if( bLoggedIn )
{
FormsAuthentication.SetAuthCookie( userName, false );
}
}
return bLoggedIn;
}


Each subsequent call will verify, who the user is, before continuing…..

string VerifyUserName(HttpApplication app)
{
string userName = app.Context.User.Identity.Name;
return userName;
}


While debugging the WebService, I tried to call the methods through Internet
Explorer (and FireFox). First I call the Login web method and then the
subsequent call. I have a breakpoint in the second call and can see that
the User.Identity.Name value is the same that I passed into the SetAuthCookie
call. So, I think I have coded the server correctly.

Now, when I try to call this from my Windows Forms application I get a
different result. The call to Login appears to behave identically. The
call to VerifyUserName fails because User.Identity is null. So, my guess
is I need to do something in my windows forms application to let each
subsequent call know who is making the call.

In my client code, I just create a new proxy to my webservice and call a
method. Is there some sort of Connection Context object that I need to
pass into each web service call? If so, how do you create it and how do you
pass it to a webservice.

Thanks in advance for your help.
 
P

Paul R

Hi Joubert. Thanks for your help.

I cannot try this until tonight. But, from what I read in your link, it
looks like I need to create a CookieContainer object for my Client
application, and assign it as the CookieContainer property on each proxy into
my web service. This, according to the link, is because a Win32
application does not support cookies by default.

I had suspected that it had something to do with the AuthCookie, but didn't
know how the client was supposed to get to it. Apparently, the
CookieContainer takes care of that for the client. Very Nice. Looks
pretty simple. I'm kind of embarrassed ;-)

Thanks again.

- Paul
 
P

Paul R

I works! Thanks.

Paul R said:
Hi Joubert. Thanks for your help.

I cannot try this until tonight. But, from what I read in your link, it
looks like I need to create a CookieContainer object for my Client
application, and assign it as the CookieContainer property on each proxy into
my web service. This, according to the link, is because a Win32
application does not support cookies by default.

I had suspected that it had something to do with the AuthCookie, but didn't
know how the client was supposed to get to it. Apparently, the
CookieContainer takes care of that for the client. Very Nice. Looks
pretty simple. I'm kind of embarrassed ;-)

Thanks again.

- Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top