Calling WebService using service reference and session maintenance

I have an asp.net web service that I am using from my ASP.NET website. I can call this from raw Javascript or jQuery to send / receive data. The web service is enabled with a session so that only authorized users can access the 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 a ServiceReference for this. But how should I maintain a session with this service? I am getting the result = failure when calling webservice. Can anyone please tell me how to manage session on webservice link in Windows Form application.

+2


source to share


1 answer


You have to use CookieContainer . Check this one , it shows an example. To add a web service reference to a WinForms / WPF project, this post is helpful.



+3


source







All Articles