views:

480

answers:

1

I have a asp.net web-service which I use from my ASP.NET website. I can call it from raw Javascript or jQuery to post/get data. The web-service is enabled with session so that only authorized users can access data.

        [WebMethod(EnableSession = true)]
        public WS_ServiceResponse SetAccountName(string account, string name)
        {
            WS_ServiceResponse osr = new WS_ServiceResponse();
            WS_ServiceResponse sessionCheck = CheckSession(Session);
            if (sessionCheck.result == WS_ServiceResponseResult.fail)
                return sessionCheck;

            osr.result = WS_ServiceResponseResult.success;
            osr.data = "";
            bool success = AccountController.SetAccountInfo(account, name);
            if (success)
            {
                osr.result = WS_ResponseResult.fail;
            }
            return osr;
        }

Now I have to create a desktop client to consume the service. I can add ServiceReference to do that. But How do I maintain session with that service? I am getting the result=fail when calling the webservice. Can anyone tell how to manage session in webservice reference in Windows Form Application.

+2  A: 

Hi,

You should use a CookieContainer. Check this post out, it shows an example. To add a web service reference on your WinForms/WPF project, this post is helpful.

_NT
Many many thanks for your links. Though it took a little bit work for me. First there is no direct "Add Web Reference" link in Visual Studio 2008. I used first the "Add Service Reference" and this thing does not have cookiecontainer. I found this post to be useful http://blogs.msdn.com/kaevans/archive/2008/03/18/where-the-heck-is-add-web-reference-in-visual-studio-2008.aspx. Now its working.
Maksud
I have included your link to my answer, to make it more complete for future readers.
_NT