Example #1
0
        internal bool Logoff(string userName, string password, SecurityToken sessionToken)
        {
            using (WSTrustChannelFactory factory = GetTrustChannelFactory())
            {
                //// Set up credentials
                if (factory.Credentials == null)
                {
                    throw new Exception("Credentails are null");
                }
                factory.Credentials.UserName.UserName  = userName;
                factory.Credentials.UserName.Password  = password;
                factory.Credentials.SupportInteractive = false;

                // Create a "request for token" SOAP message.
                // We want the security server to Issue us with a token
                RequestSecurityToken rst = new RequestSecurityToken(RequestTypes.Cancel);
                // the token we want to cancel
                rst.CancelTarget = new SecurityTokenElement(sessionToken);


                // Create the communicaiton channel
                IWSTrustChannelContract channel = factory.CreateChannel();

                // Cancel token
                // ReSharper disable once UnusedVariable
                RequestSecurityTokenResponse response = channel.Cancel(rst);
                return(response.RequestedTokenCancelled);
            }
        }
Example #2
0
        public bool Logoff(string userName, string password, SecurityToken sessionToken, string securityServerURL)
        {
            using (WSTrustChannelFactory factory = GetTrustChannelFactory(securityServerURL))
            {
                if (factory.Credentials == null)
                {
                    throw new Exception("Credentails are null");
                }
                factory.Credentials.UserName.UserName  = userName;
                factory.Credentials.UserName.Password  = password;
                factory.Credentials.SupportInteractive = false;

                RequestSecurityToken rst = new RequestSecurityToken(RequestTypes.Cancel)
                {
                    CancelTarget = new SecurityTokenElement(sessionToken)
                };

                IWSTrustChannelContract channel = factory.CreateChannel();

                RequestSecurityTokenResponse response = channel.Cancel(rst);

                return(response.RequestedTokenCancelled);
            }
        }