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

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

http://blog.programframework.com/wp-content/uploads/2014/12/1.png

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

http://blog.programframework.com/wp-content/uploads/2014/12/2.png

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)

http://blog.programframework.com/wp-content/uploads/2014/12/3.png
**

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();

}

From: http://blog.programframework.com/projectserver/projectserver2013/how-to-create-a-remote-event-handler-for-project-server-2013-project-online/