Project Online, Project Server 2013

How to Create a Remote Event Handler for Project Server 2013 / Project Online

| | Leave a comment

There is almost no information regarding the creation of a Project Server Remote Event Handler, which led me to make efforts on demystifying the implementation of it.

Part 1 – Create a Visual Studio Project of type Empty Web Site
1

Part 2 – Add a new item to it of type WCF Service
2

Part 3 – Create a ClassLibrary that inherits from IProjectEventReceiverRemote

namespace PF.RemoteEvents{
public class ProjectServerRemoteEvents : IProjectEventReceiverRemote

Part 4 – As it’s an implementation of an Interface, you must declare all the remaining interface methods:

public void OnActivityUpgradedRemote(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, Guid eventHandlerUid, ActivityUpgradedEventArgs e) {
            throw new NotImplementedException();
}

public ActivityUpgradingEventArgs OnActivityUpgradingRemote(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, Guid eventHandlerUid, ActivityUpgradingEventArgs e) {
            throw new NotImplementedException();
}

public void OnAddedRemote(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, Guid eventHandlerUid, ProjectPostUpdatedEventArgs e) {
            throw new NotImplementedException();
}

Part 5 – Implement your desired Event:

public void OnPublishedRemote(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, Guid eventHandlerUid, ProjectPostPublishEventArgs e) {
            //Do Some Stuff
}

Part 6 – Deploy your website to a location that is reachable by the Project Server

Part 7 – Register your event on PWA

For the registration part we could use the CSOM – Client Side Object Model or the Central Administration.

The Central Administration will only be available on Project Server 2013 and not on Project Online.

Part 7.1 – Central Administration

  1. Navigate to: General Application Settings
  2. Under PWA Settings select Manage
  3. Select Server Side Event Handlers
  4. Under the proper Event Source Category select the corresponding Category for your Event. In the sample above Event Source: Project, Event: OnPublished
    1. Click on the Corresponding Event
  5. Click on New Event Handler
    1. Fill in the Name, Class Name and Endpoint Url (all of this are required for the Remote Event work)

3
Part 7.2 – CSOM Registration

Alternatively you could register the event using CSOM.

  1. Create a Visual Studio Project of type Console Application
  2. Add a Reference to the Microsoft.ProjectServer.Client.dll
  3. Write the Following Code for the Registration

​protected void btnRegister_Click(object sender, EventArgs e) {
ProjectContext projectContext = new ProjectContext(ProjectServerPWAUrl);
projectContext.Credentials = new System.Net.NetworkCredential(XXXX_USERNAME, XXX_PASSWORD, XXX_DOMAIN);
projectContext.EventHandlers.Add(new EventHandlerCreationInformation() {
EventId = (int)PSEventID.ProjectPublished,
EndpointUrl = BaseUrl + “/ProjectRemoteEvent.svc”,
Id = Guid.NewGuid(),
Name = “PF.ProjectPublished-Remote”,
ClassName = “PF.RemoteEvents.ProjectServerRemoteEvents”
});
projectContext.EventHandlers.Update();
projectContext.ExecuteQuery();
}