次の方法で共有


LoginForms.Logoff Method

Log off the current Project Server user who logged on with Forms authentication.

Namespace:  [LoginForms Web service]
Service reference: http://ServerName:32843/[Project Service Application GUID]/PSI/LoginForms.svc
Web service reference: http://ServerName/ProjectServerName/_vti_bin/PSI/LoginForms.asmx?wsdl

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/LoginForms/Logoff", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/LoginForms/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/LoginForms/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub Logoff
'Usage
Dim instance As LoginForms

instance.Logoff()
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/LoginForms/Logoff", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/LoginForms/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/LoginForms/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void Logoff()

Remarks

After a successful log off, set the CookieContainer property to a null reference (Nothing in Visual Basic) for other PSI Web service objects in the same application.

Examples

The LogonPS method in the following example handles logon and the LogoffPS method handles logoff for Forms authentication.

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace LoginDemo
{
    class LoginUtils
    {
        const string LOGINWINDOWS = "_vti_bin/PSI/LoginWindows.asmx";
        const string LOGINFORMS = "_vti_bin/PSI/LoginForms.asmx";

        private static LoginWindowsWebSvc.LoginWindows loginWindows =
            new LoginWindowsWebSvc.LoginWindows();
        private static LoginFormsWebSvc.LoginForms loginForms =
            new LoginFormsWebSvc.LoginForms();
        private CookieContainer cookies = new CookieContainer();

        private string baseUrl; // Example: https://ServerName/ProjectServer/

        public LoginUtils()
        {
        }

        public string BaseUrl
        {
            get
            {
                return baseUrl;
            }
        }

        public CookieContainer Cookies
        {
            get
            {
                return loginForms.CookieContainer;
            }
        }

        // Log on Project Server.
        // Returns true for successful logon.
        public bool LogonPS(bool useWinLogon, string bUrl,
            string userName, string password)
        {
            bool logonSucceeded = false;
            baseUrl = bUrl;

            if (useWinLogon)
            {
                loginWindows.Url = baseUrl + LOGINWINDOWS;
                loginWindows.Credentials = CredentialCache.DefaultCredentials;

                if (loginWindows.Login()) logonSucceeded = true;
            }
            else  // Use LoginForms
            {
                loginForms.Url = baseUrl + LOGINFORMS;
                loginForms.CookieContainer = cookies;

                if (loginForms.Login(userName, password)) logonSucceeded = true;
            }
            return logonSucceeded;
        }

        // Log off Project Server.
        // Returns true for successful logoff.
        public bool LogoffPS(bool useWinLogon)
        {
            bool loggedOff = true;
            if (useWinLogon)
            {
                loginWindows.Logoff();
            }
            else
            {
                loginForms.Logoff();
            }
            return loggedOff;
        }
    }
}

The following code instantiates and uses the LoginUtils class for Forms authentication. The project object is an example that shows how to remove the user context for a PSI Web service.

private bool windowsAuth = false;  // Use Project Server authentication
private static LoginUtils loginUtils = new LoginUtils();
public static ProjectWebSvc.Project project = 
    new ProjectWebSvc.Project();
. . .
private void LogOff()
{
    bool loggedOff = false;
    string errMess = "";
    try
    {
        loggedOff = loginUtils.LogoffPS(windowsAuth);
    }
    catch (SoapException ex)
    {
        errMess = ex.Message.ToString();
    }
    catch (WebException ex)
    {
        errMess = ex.Message.ToString();
    }
    if (loggedOff)
    {
        RemoveContextInfo();
    }
    else
    {
        MessageBox.Show(errMess, "Logoff Error", MessageBoxButtons.OK, 
            MessageBoxIcon.Error);
    }
}

/// <summary>
/// Remove the user credentials or logon cookie from each PSI Web service object.
/// </summary>
public void RemoveContextInfo()
{
    if (windowsAuth)
    {
        project.Credentials = null;
    }
    else
    {
        project.CookieContainer = null;
    }
}

See Also

Reference

LoginForms Class

LoginForms Members

LoginForms Web Service