public bool LogoffPS(string baseUrl) { bool loggedOff = true; try { const string LOGINWINDOWS = "/_vti_bin/PSI/LoginWindows.asmx"; WebLoginReference.LoginWindowsSoapClient clientLogin = new WebLoginReference.LoginWindowsSoapClient(Binding, endPointAdress(baseUrl, LOGINWINDOWS)); clientLogin.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain); clientLogin.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; clientLogin.Logoff(); loggedOff = true; } catch (System.Web.Services.Protocols.SoapException ex) { MessageBox.Show(ex.Message.ToString(), "Logon Error", MessageBoxButtons.OK, MessageBoxIcon.Error); loggedOff = false; } catch (System.Net.WebException ex) { MessageBox.Show(ex.Message.ToString(), "Logoff Error", MessageBoxButtons.OK, MessageBoxIcon.Error); loggedOff = false; } return(loggedOff); }
public bool Logon(string baseUrl) { const string LOGINWINDOWS = "/_vti_bin/PSI/LoginWindows.asmx"; bool logonSucceeded = false; ClientContext clientContext = new ClientContext(baseUrl); //var credentials = new NetworkCredential(this.User, this.PassWord, this.Domain); //clientContext.Credentials = credentials; //CredentialCache.DefaultCredentials; ////clientContext.RequestTimeout = timeOutConnection; //clientContext.Load(clientContext.Web); //clientContext.ExecuteQuery(); //Logged = true; try { var endpoint = endPointAdress(baseUrl, LOGINWINDOWS); WebLoginReference.LoginWindowsSoapClient clientLogin = new WebLoginReference.LoginWindowsSoapClient(Binding, endpoint); clientLogin.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain); clientLogin.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; //SvcLoginWindows.LoginWindows login = new SvcLoginWindows.LoginWindows(); //login.Url = endpoint.ToString(); if (clientLogin.Login()) { logonSucceeded = true; } } catch (System.Web.Services.Protocols.SoapException ex) { MessageBox.Show(ex.Message.ToString(), "Logon Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (System.Net.WebException ex) { MessageBox.Show(ex.Message.ToString(), "Logon Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(logonSucceeded); }