예제 #1
0
        private string GetSessionTicket(ref PwsProjectorServicesClient pwsProjectorServices, string accountCode, string userName, string password)
        {
            PwsAuthenticateRs rs = pwsProjectorServices.PwsAuthenticate(new PwsAuthenticateRq()
            {
                AccountCode = accountCode,
                UserName    = userName,
                Password    = password
            });

            string sessionTicket = rs.SessionTicket;

            //if request fails bounce out
            if (rs.Status != RequestStatus.Ok)
            {
                return(null);
            }

            //To prevent infinite recursion, only try to reconnect if RedirectUrl is different from current url
            if (rs.RedirectUrl != null && pwsProjectorServices.Endpoint.Address.Uri.AbsoluteUri.StartsWith(rs.RedirectUrl))
            {
                return(null);
            }

            //If a RedirectUrl was returned then your account data is on a different server. Retry with new url.
            if (rs.RedirectUrl != null)
            {
                Uri    uri        = new Uri(pwsProjectorServices.Endpoint.Address.Uri.ToString());
                string newUriText = rs.RedirectUrl + uri.LocalPath;
                pwsProjectorServices = new PwsProjectorServicesClient("BasicHttpBinding_IPwsProjectorServices", newUriText);
                string session = GetSessionTicket(ref pwsProjectorServices, accountCode, userName, password);
                return(session);
            }
            return(rs.SessionTicket);
        }
예제 #2
0
        public bool AuthenticateUser(string accountCode, string userName, string password)
        {
            try
            {
                authenticationResponse = pwsProjectorServices.PwsAuthenticate(new PwsAuthenticateRq()
                {
                    AccountCode = accountCode,
                    UserName    = userName,
                    Password    = password
                });

                //If request fails bounce out;
                return(authenticationResponse.Status == RequestStatus.Ok && authenticationResponse.SessionTicket != null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                return(false);
            }
        }