如何认证到Project Online PSI服务

本文关键字:Project Online PSI 服务 何认证 认证 | 更新日期: 2023-09-27 18:10:56

我在sharepoint.com上有MS项目在线帐户,我需要从客户端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时。登录我得到SoapException消息:"值不能为空。参数名称:account"。内部异常xml是:

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

我做错了什么?

如何认证到Project Online PSI服务

您可以使用:

new SharePointOnlineCredentials(username, secpassword);

代替

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

首先:安装所需的客户端SDK

  • SharePoint Client SDKhttp://www.microsoft.com/en-au/download/details.aspx?id=35585
  • Project 2013 SDK:http://www.microsoft.com/en-au/download/details.aspx?id=30435
第二步:将引用添加到项目
  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);
    }
}

Project Online PSI服务的认证在这篇优秀的文章中进行了描述:http://www.umtsoftware.com/blog/how-to-project-online-psi/