【问题标题】:How to authenticate to Project Online PSI services?如何对 Project Online PSI 服务进行身份验证?
【发布时间】:2015-09-03 10:05:46
【问题描述】:

我在 sharepoint.com 上拥有 MS Project Online 帐户,我需要从客户端 C# 代码到 PSI 服务进行身份验证以获取项目列表。

服务器具有基于表单的身份验证。我正在尝试通过下一个代码登录:

SvcLoginForms.LoginForms loginform = new SvcLoginForms.LoginForms();
loginform.Credentials = new NetworkCredential("admin@myserver.onmicrosoft.com", "password");            
loginform.Url = "https://myserver.sharepoint.com/sites/pwa/_vti_bin/PSI/Project.asmx";
loginform.Login("admin@myserver.onmicrosoft.com", "password");

当我执行 loginform.Login 时,我收到 SoapException 消息:“值不能为空。参数名称:帐户”。内部异常 xml 是:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Value cannot be null.

参数名称:账号

我做错了什么?

【问题讨论】:

    标签: c# office365 ms-project-server-2013


    【解决方案1】:

    你可以使用:

    new SharePointOnlineCredentials(username, secpassword);
    

    而不是

    new NetworkCredential("admin@myserver.onmicrosoft.com", "password");
    

    首先:安装所需的Client SDK

    第二:添加对你项目的引用

    1. Microsoft.SharePoint.Client.dll
    2. Microsoft.SharePoint.Client.Runtime.dll
    3. Microsoft.ProjectServer.Client.dll

    你可以在%programfiles%\Common Files\microsoft shared\Web Server Extensions\15\ISAPI找到这些dll 和%programfiles(x86)%\Microsoft SDKs\Project 2013\REDIST

    这里是示例代码:

    using System;
    using System.Security;
    using Microsoft.ProjectServer.Client;
    using Microsoft.SharePoint.Client;
    
    public class Program
    {
        private const string pwaPath = "https://[yoursitehere].sharepoint.com/sites/pwa";
        private const string username ="[username]";
        private const string password = "[password]";
        static void Main(string[] args)
        {
            SecureString secpassword = new SecureString();
            foreach (char c in password.ToCharArray()) secpassword.AppendChar(c);
    
    
            ProjectContext pc = new ProjectContext(pwaPath);
            pc.Credentials = new SharePointOnlineCredentials(username, secpassword);
    
            //now you can query
            pc.Load(pc.Projects);
            pc.ExecuteQuery();
            foreach(var p in pc.Projects)
            {
                Console.WriteLine(p.Name);
            }
    
            //Or Create a new project
            ProjectCreationInformation newProj = new ProjectCreationInformation() {
                Id = Guid.NewGuid(),
                Name = "[your project name]",
                Start = DateTime.Today.Date
            };        
            PublishedProject newPublishedProj = pc.Projects.Add(newProj);
            QueueJob qJob = pc.Projects.Update();
    
            JobState jobState = pc.WaitForQueue(qJob,/*timeout for wait*/ 10);
    
        }
    
    }
    

    【讨论】:

    • 虽然给定的代码片段有效,但它不能回答原始问题。它解释了如何通过 CSOM 连接,而问题是如何通过 PSI 连接。例如,我必须连接并完全使用 PSI。
    【解决方案2】:

    这篇优秀的文章描述了对 Project Online PSI 服务的身份验证:http://www.umtsoftware.com/blog/how-to-project-online-psi/

    【讨论】:

      猜你喜欢
      • 2022-10-13
      • 2011-08-29
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 2012-07-28
      • 2011-02-20
      • 2011-09-03
      • 1970-01-01
      相关资源
      最近更新 更多