Groups | Blog | Home
all groups > asp.net webservices > november 2005 >

asp.net webservices : WebService Client Context



Paul R
11/29/2005 7:27:04 AM
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.
Paul R
11/30/2005 10:19:15 AM
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

[quoted text, click to view]
Joubert Nel
11/30/2005 11:04:38 AM
Hello Paul,

Have a look at
http://www.dotnet247.com/247reference/a.aspx?u=http://www.dotnetjunkies.com/Tutorial/5D8B6D51-97B7-4825-B919-49A721A3FDF6.dcik

There is a section about using Forms authentication and IIS-based web
services from a WinForms app. May help you with the issue below.

Regards
Joubert


[quoted text, click to view]

Paul R
12/1/2005 6:26:04 AM
I works! Thanks.

[quoted text, click to view]
AddThis Social Bookmark Button