max
max

Reputation: 1712

Calling WebService using Service Reference and Maintain Session

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.

Upvotes: 2

Views: 4630

Answers (1)

NT_
NT_

Reputation: 2670

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.

Upvotes: 3

Related Questions