次の方法で共有


Admin.ReadDepartments メソッド

Project Web Appインスタンスで定義されている部門の一覧を読み取ります。

名前空間:  WebSvcAdmin
アセンブリ:  ProjectServerServices (ProjectServerServices.dll 内)

構文

'宣言
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Admin/ReadDepartments", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Admin/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Admin/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadDepartments ( _
    language As Integer _
) As DepartmentsDataSet
'使用
Dim instance As Admin
Dim language As Integer
Dim returnValue As DepartmentsDataSet

returnValue = instance.ReadDepartments(language)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Admin/ReadDepartments", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Admin/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Admin/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public DepartmentsDataSet ReadDepartments(
    int language
)

パラメーター

  • language
    型: System.Int32

    国または地域の言語を示す、主言語識別子 (LCID) を指定します。

戻り値

型: WebSvcAdmin.DepartmentsDataSet

注釈

部門、部門テーブル、エンタープライズ ユーザー設定フィールドと参照テーブル] ページでProject Web App (https://ServerName/ProjectServerName/_layouts/pwa/Admin/CustomizeFields.aspx) で定義できます。

プロジェクト サーバーのアクセス許可

権限

説明

LogOnToProjectServerFromProjectProfessional

エンタープライズ グローバル テンプレートをロードすることができます。グローバル アクセス権。

ManageUsersAndGroups

追加、変更、またはユーザーを削除および Project Server のセキュリティ グループを管理することができます。グローバル アクセス権。

ViewProjectCenter

プロジェクト センターにアクセスすることができます。グローバル アクセス権。

ViewResourceCenter

リソース センターにアクセスすることができます。グローバル アクセス権。

ManageEnterpriseCustomFields

エンタープライズ ユーザー設定フィールドと参照テーブル値の定義を変更することができます。グローバル アクセス権。

NewProject

新しいプロジェクトを Project Server データベースに追加することができます。グローバル アクセス権。

ReadDepartmentsメソッドの使用例を次に示します。例では、ProjectServerServices.dll プロキシ アセンブリ内のSvcAdminの名前空間を使用します。ReadDepartmentsを使用するコードを返しますDepartmentsDataSet。アプリケーションは、結果を XML ファイルに書き込みます。

注意

ConfigClientEndpointsメソッドは、WCF のバインディング、動作、およびエンドポイントの設定を app.config ファイルを使用します。PSI プロキシ アセンブリと app.config ファイルを作成する方法の詳細については、 Project 2013 での WCF ベースのコード サンプルの前提条件を参照してください。

using System;
using System.Text;
using System.ServiceModel;
using System.Xml;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.TestAdmin
{
    class Program
    {
        private const string ENDPOINT_ADMIN = "basicHttp_Admin";
        // Change the output directory to match the output directory of your computer.
        private const string OUTPUT_FILES = @"E:\Project\Samples\Output\";

        private static SvcAdmin.AdminClient adminClient;

        private static string outFilePath;
 
        static void Main(string[] args)
        {

            outFilePath = OUTPUT_FILES + "DepartmentsDataSet.xml";
            ConfigClientEndpoints(ENDPOINT_ADMIN);

            int lcid = 1033;  // The Department lookup table is in English.
            
            try
            {
                // Here is the thing that we are trying to do.
                SvcAdmin.DepartmentsDataSet deptDS = adminClient.ReadDepartments(lcid);
                deptDS.WriteXml(outFilePath);

            }
            catch(FaultException fault)
            {
                // Use the WCF FaultException, because the ASMX SoapException does not 
                // exist in a WCF-based application.
                WriteFaultOutput(fault);
            }
            Console.Write("\nPress any key to exit... ");
            Console.ReadKey();
        }


        // Extract a PSClientError object from the WCF FaultException object, and
        // then display the exception details and each error in the PSClientError stack.
        private static void WriteFaultOutput(FaultException fault)
        {
            string errAttributeName;
            string errAttribute;
            string errOut;
            string errMess = "".PadRight(30, '=') + "\r\n"
                + "Error details: " + "\r\n";

            PSLibrary.PSClientError error = Helpers.GetPSClientError(fault, out errOut);
            errMess += errOut;

            PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
            PSLibrary.PSErrorInfo thisError;

            for (int i = 0; i < errors.Length; i++)
            {
                thisError = errors[i];
                errMess += "\r\n".PadRight(30, '=') + "\r\nPSClientError output:\r\n";
                errMess += thisError.ErrId.ToString() + "\n";

                for (int j = 0; j < thisError.ErrorAttributes.Length; j++)
                {
                    errAttributeName = thisError.ErrorAttributeNames()[j];
                    errAttribute = thisError.ErrorAttributes[j];
                    errMess += "\r\n\t" + errAttributeName
                        + ": " + errAttribute;
                }
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(errMess);
            Console.ResetColor();
        }

        // Use the endpoints that are defined in app.config to configure the client.
        public static void ConfigClientEndpoints(string endpt)
        {
            if (endpt == ENDPOINT_ADMIN)
                adminClient = new SvcAdmin.AdminClient(ENDPOINT_ADMIN);
        }            
    }


    // Helper method: GetPSClientError.
    class Helpers
    {
        /// <summary>
        /// Extract a PSClientError object from the ServiceModel.FaultException,
        /// for use in output of the GetPSClientError stack of errors.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="errOut">Shows that FaultException has more information 
        /// about the errors than PSClientError has. FaultException can also contain 
        /// other types of errors, such as failure to connect to the server.</param>
        /// <returns>PSClientError object, for enumerating errors.</returns>
        public static PSLibrary.PSClientError GetPSClientError(FaultException e,
                                                               out string errOut)
        {
            const string PREFIX = "GetPSClientError() returns null: ";
            errOut = string.Empty;
            PSLibrary.PSClientError psClientError = null;

            if (e == null)
            {
                errOut = PREFIX + "Null parameter (FaultException e) passed in.";
                psClientError = null;
            }
            else
            {
                // Get a ServiceModel.MessageFault object.
                var messageFault = e.CreateMessageFault();

                if (messageFault.HasDetail)
                {
                    using (var xmlReader = messageFault.GetReaderAtDetailContents())
                    {
                        var xml = new XmlDocument();
                        xml.Load(xmlReader);

                        var serverExecutionFault = xml["ServerExecutionFault"];
                        if (serverExecutionFault != null)
                        {
                            var exceptionDetails = serverExecutionFault["ExceptionDetails"];
                            if (exceptionDetails != null)
                            {
                                try
                                {
                                    errOut = exceptionDetails.InnerXml + "\r\n";
                                    psClientError =
                                        new PSLibrary.PSClientError(exceptionDetails.InnerXml);
                                }
                                catch (InvalidOperationException ex)
                                {
                                    errOut = PREFIX + "Unable to convert fault exception info ";
                                    errOut += "a valid Project Server error message. Message: \n\t";
                                    errOut += ex.Message;
                                    psClientError = null;
                                }
                            }
                            else
                            {
                                errOut = PREFIX + "The FaultException e is a ServerExecutionFault, "
                                    + "but does not have ExceptionDetails.";
                            }
                        }
                        else
                        {
                            errOut = PREFIX + "The FaultException e is not a ServerExecutionFault.";
                        }
                    }
                }
                else // No detail in the MessageFault.
                {
                    errOut = PREFIX + "The FaultException e does not have any detail.";
                }
            }
            errOut += "\r\n" + e.ToString() + "\r\n";
            return psClientError;
        }
    }
}

サンプル アプリケーションを保存する DepartmentsDataSet.xml の出力ファイルの例を次に示します。

注意

例では、返される、部門名は部門のProject Web Appのインスタンスで定義されている固有です。

<?xml version="1.0" standalone="yes"?>
<DepartmentsDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/DepartmentsDataSet/">
  <Departments>
    <DEPARTMENT_UID>83125fbf-5c09-4b93-800a-09681bbf7612</DEPARTMENT_UID>
    <DEPARTMENT_NAME>Marketing</DEPARTMENT_NAME>
    <DEPARTMENT_FULLNAME>Marketing</DEPARTMENT_FULLNAME>
  </Departments>
  <Departments>
    <DEPARTMENT_UID>a47930d6-b89d-4f3a-b4e3-522015fe82a1</DEPARTMENT_UID>
    <DEPARTMENT_NAME>Testing</DEPARTMENT_NAME>
    <DEPARTMENT_FULLNAME>Testing</DEPARTMENT_FULLNAME>
  </Departments>
  <Departments>
    <DEPARTMENT_UID>cca85763-9376-4ef7-b4f2-a2b661b9846b</DEPARTMENT_UID>
    <DEPARTMENT_NAME>UA</DEPARTMENT_NAME>
    <DEPARTMENT_FULLNAME>UA</DEPARTMENT_FULLNAME>
  </Departments>
  <Departments>
    <DEPARTMENT_UID>41d056ca-497f-4e4a-8855-e118b667fcc8</DEPARTMENT_UID>
    <DEPARTMENT_NAME>Planning</DEPARTMENT_NAME>
    <DEPARTMENT_FULLNAME>Planning</DEPARTMENT_FULLNAME>
  </Departments>
  <Departments>
    <DEPARTMENT_UID>96e4522f-2d4e-4026-9ec0-ede9c182dda8</DEPARTMENT_UID>
    <DEPARTMENT_NAME>Development</DEPARTMENT_NAME>
    <DEPARTMENT_FULLNAME>Development</DEPARTMENT_FULLNAME>
  </Departments>
</DepartmentsDataSet>

関連項目

参照先

Admin クラス

Admin メンバー

WebSvcAdmin 名前空間