Updated: Part 2 of this article, updated for SharePoint 2016 / Project Online.
When using Project Server on-premises, custom applications were bound to use PSI services. In Project Online 2013, the interface of choice is now CSOM, and officially, PSI is no longer supported.
However CSOM has its own limitations and it doesn’t expose (yet) the full functionality of PSI, so if you’re looking for calling PSI in Project Online, you basically need to:
1. Get the authentication cookie for the account you’re going to authenticate with.
2. Set the authentication cookie on the request made by your services.
This could come in very helpful when you’re migrating to Online but have a handful of already made customizations using PSI.
Getting the authentication cookie is straightforward. Just use the SharePointOnlineCredentials class, and get the cookie:
String projectOnlineUrl = "https://yourtenant.sharepoint.com/sites/pwa";
String userName = "youruser@yourdomain.com";
String passWord = "yourpassword";
SharePointOnlineCredentials spoCred = new SharePointOnlineCredentials(userName, SecureStringFromString(passWord));
String authCookie = spoCred.GetAuthenticationCookie(new Uri(projectOnlineUrl));
Setting the cookie on the WCF service requests needs a bit more work. However, the article here helps, so after creating the CookieBehavior and CookieMessageInspector classes as described in the article, we can attach them to our clients. To simplify, we can create a custom WcfClientBase class that will do this automatically for us.
class WcfClientBase<TServiceContract> : ClientBase<TServiceContract>, TServiceContract where TServiceContract: class
{
public WcfClientBase(String authCookie, String serviceUrl)
: base(
new ServiceEndpoint(ContractDescription.GetContract(typeof(TServiceContract)))
{
Binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport),
Address = new EndpointAddress(new Uri(serviceUrl + "/_vti_bin/psi/projectserver.svc"))
})
{
base.Endpoint.EndpointBehaviors.Add(new CookieBehavior(authCookie));
}
}
Then, we can define proxies for each interface we use, and implement the methods by calling them on the base.Channel
class ProjectClient : WcfClientBase, IProject
{
...
public ProjectDataSet ReadProjectList()
{
return base.Channel.ReadProjectList();
}
}
Last, we can invoke the service as such:
IProject projClient = new ProjectClient(authCookie, projectOnlineUrl);
ProjectDataSet pds = projClient.ReadProjectList();
Download the PSIOnline code sample.
What do you think?
Great post, Ionut!
your Example works like a charm.
According to the “Project 2013 PSI reference overview” [1] it is not supported. But it looks like you are using this technic in your products at UMT. Do you have any statement from Microsoft if this is supported?
[1] http://msdn.microsoft.com/en-us/library/office/ms488627(v=office.15).aspx
Kurt,
This is not supported as clearly mentioned at the beginning of the post. However it provides a solution where CSOM lacks the required functionality.
Use this approach at your own risk.
Thank you Ionut!
Can you please repost the code sample link? It’s not working any more.
Nankai,
I updated the link, it should work now.
Hi UMT,
Great post, but it does not seem to work.
I have a Project Online PWA instance (in SharePoint Permissions Mode, is this the problem), in which I am the Site Collection Administrator and I’m in the Project Web App Administrators group.
The code runs through to “ReadProjectList” and throws a “Unhandled Communication Fault occurred”.
Do you have any extra tips?
Thanks
Adrian
The Project PSI has been deprecated since writing of this post. Please see https://msdn.microsoft.com/en-us/library/office/ee767690.aspx which says:
“Project PSI The Project class of the PSI is deprecated. For all new development, use the Project CSOM. Project Server 2013 apps that use the Project PSI will continue to work, but Project Online apps will need to replace any Project-class PSI methods with their equivalent CSOM methods.”
Hi, I know the Project class of PSI is deprecated. But what about enterprise resources? Is it also deprecated. I got the same error message “Unhandled Communication Fault occurred” when trying to update resource standard rate.
Do you know if Microsoft.Office.Project.Server.Interfaces have been depreciated? Trying to build the sample code but it cannot find any Interfaces from Microsoft.Office.Project.Server vers 1.0.1.