With SharePoint Online, Microsoft came up with Remote Event Receivers, a way to support the same use cases but keeping the code outside of SharePoint. Recently, Microsoft decided to embrace industry standards and added support for webhooks in SharePoint.
3. IT Deputy Director @ Pestana Hotel Group
Office Servers and Services MVP
SharePoint for 11+ years
Speaker & author
https://andrevala.com
/in/andrevala
@atomicvee
andre.vala@gmail.com
4. Event
Receivers Conclusions
3 SLIDES
LEVEL: 100
ALL
7 SLIDES
LEVEL: 200
DEV
15 SLIDES + 1 DEMO
LEVEL: 300
DEV
15 SLIDES + 1 DEMO
LEVEL: 300
DEV
7 SLIDES
LEVEL: 100
ALL
Remote
Event
Receivers
SharePoint
Webhooks
Event
Handling in
SharePoint
6. Respond to user actions and modifications to content
Add validation logic for columns on list items
Cleanup and format content as it is entered by users
Calculate and store aggregated values
Initialize a host web with new lists during add-in installation
9. Server-side event handling
Implemented using an event receiver class
Registration requires referencing of the event receiver class
Event receivers are deployed by SharePoint solution in a .NET
assembly
Loaded into SharePoint worker process
10. Executed before data is committed to the Content DB
Opportunity for pre-processing like validations
Opportunity to cancel the event
Run in the same process and thread that triggered the event
Block the execution of the current thread
UI will be held up
Avoid complex time-consuming processing logic
11. Executed after data is committed to the Content DB
Cannot be cancelled
Opportunity for post-processing like notifications
Run on a background thread and do not block the UI
This behaviour can be changed by updating the synchronization property of the the event
receiver to synchronous
12. Site/Web Events
Site Delete
Web Delete
Web Move
Web Add (2010)
Web Provision (2010)
Feature Events
Feature Activate
Feature Deactivate
Feature Install
Feature Uninstall
Feature Upgrade
Workflow Events
Workflow Start (2010)
Workflow Postpone (2010)
Workflow Complete (2010)
Entity Instance Events
Entity Instance Add (2013)
Entity Instance Delete (2013)
Entity Instance Update
(2013)
Add-In Lifecycle Events
Add-In Install (2013)
Add-In Upgrade (2013)
Add-In Uninstall (2013)
List Events
List Add (2010)
List Delete (2010)
Email Reception
List Schema Events
Field Add
Field Delete
Field Update
List Item Events
Item Add
Item Delete
Item Update
Item Attachment Add
Item Attachment Delete
Item Check In
Item Check Out
Item Uncheck Out
Item File Move
Item File Convert
Item Version Delete (2013)
Security Events (2013)
Group Add
Group Update
Group Delete
Group User Add
Group User Delete
Role Definition Add
Role Definition Delete
Role Definition Update
Role Assignment Add
Role Assignment Delete
Role Assignment Update
Break Inheritance
Reset Inheritance
13. Declaratively for List and Content Type binding
Using the object model for all bindings
SPWeb new SPSite "http://localhost"
SPEventReceiverDefinition
"Receiver.Class1"
"Receiver, Version=1.0.0.0, Culture=neutral, PublicKeyToken =10b23036c9b36d6d"
SPEventReceiverType
14. Inherit from one of the base classes
Override the corresponding event methods
16. Event handler code runs in remote web (not SharePoint)
SharePoint calls web service in remote web to trigger event
Must be accessible by anonymous users
Supported remote events are a subset of server-side events
Remote “before” events implemented as two-way events
Remote “after” events implemented as one-way events
17. Modeled as two-way events
Execution flow goes to remote web and then back to SharePoint
Client is blocked while event processing occurs in remote web
Sample execution flow for two-way event
1. Client attempts action which triggers an event (e.g. update item)
2. SharePoint host calls to web service in remote web
3. SharePoint host blocks until call returns from remote web
4. SharePoint host commits action and returns to Client
Two Way Event (aka before event)
Client
SharePoint
Host
Remote
Web
1 2
34
18. Modeled as one-way events
Execution flow goes to remote web but does not return
Unlike “before” events, after events do not block client response
Sample execution flow for one-way event
1. Client attempts action which triggers an event (e.g. update item)
2. SharePoint host commits action and returns to Client
3. SharePoint host executes one-way WCF call on remote web
One Way Event (aka after event)
Client
SharePoint
Host
Remote
Web
1
3
2
19. Site/Web Events
Site Delete
Web Delete
Web Move
Web Add
Web Provision
Feature Events
Feature Activate
Feature Deactivate
Feature Install
Feature Uninstall
Feature Upgrade
Workflow Events
Workflow Start (2010)
Workflow Postpone (2010)
Workflow Complete (2010)
Entity Instance Events
Entity Instance Add
Entity Instance Delete
Entity Instance Update
Add-In Lifecycle Events
Add-In Install
Add-In Upgrade
Add-In Uninstall
List Events
List Add
List Delete
Email Reception
List Schema Events
Field Add
Field Delete
Field Update
List Item Events
Item Add
Item Delete
Item Update
Item Attachment Add
Item Attachment Delete
Item Check In
Item Check Out
Item Uncheck Out
Item File Move
Item File Convert
Item Version Delete
Security Events
Group Add
Group Update
Group Delete
Group User Add
Group User Delete
Role Definition Add
Role Definition Delete
Role Definition Update
Role Assignment Add
Role Assignment Delete
Role Assignment Update
Break Inheritance
Reset Inheritance
20. Event receivers must be registered with SharePoint host
Registration can be declarative with XML for events occurring in app web
Registration for events occurring in host web requires writing procedural code
21. Remote event receiver implemented with .svc file
Event receiver code written as C# code code-behind .svc file
Event receiver is a class that implements IRemoteEventService
ProcessEvent method executes when two-way event is triggered
ProcessOneWayEvent method executes when one-way event is triggered
22. Passed as parameter
Provides you with contextual information about the current event
Makes it possible to determine event type and event target object
Makes it possible to read user input to perform validation
23. ProcessEvent must return SPRemoteEventResult object
Makes it possible to cancel user action when user input is invalid
Makes it possible to update user input when processing a “before” event
24.
25.
26. SharePoint add-in model support add-in events
Add-in events for installation, upgrade and uninstall
Added to add-in project using property sheet
Implemented as a remote event receiver
App Installed event
App Installed event must complete within 30 seconds
SharePoint will call the receiver 3 times before failing
28. Debugging in Office 365
Addresses with http://localhost will not work
You must use a Azure Relay to expose your service
Visual Studio has native support for debugging via Azure Relay (previously Azure Services Bus)
31. A way to be notified of a done change
Push model instead of Pull model
Universal model used by many services (WordPress, GitHub,
MailChimp, ...)
First made available in OneDrive and Outlook
Now available in SharePoint Online
39. SharePoint
Service
Your WebHook
notification
service endpoint
Application
Storage Queue WebJob
SQL Azure DB
POST https://{your host}/your/webhook/service
POST /_api/web/lists('list-id')/subscriptions
Grab “CurrentChangeToken” from list
Persist token per
subscription
Persist last used token per subscription
Grab change token from DB
40. Site/Web Events
Site Delete
Web Delete
Web Move
Web Add
Web Provision
Feature Events
Feature Activate
Feature Deactivate
Feature Install
Feature Uninstall
Feature Upgrade
Workflow Events
Workflow Start (2010)
Workflow Postpone (2010)
Workflow Complete (2010)
Entity Instance Events
Entity Instance Add
Entity Instance Delete
Entity Instance Update
Add-In Lifecycle Events
Add-In Install
Add-In Upgrade
Add-In Uninstall
List Events
List Add
List Delete
Email Reception
List Schema Events
Field Add
Field Delete
Field Update
List Item Events
Item Add
Item Delete
Item Update
Item Attachment Add
Item Attachment Delete
Item Check In
Item Check Out
Item Uncheck Out
Item File Move
Item File Convert
Item Version Delete
Security Events
Group Add
Group Update
Group Delete
Group User Add
Group User Delete
Role Definition Add
Role Definition Delete
Role Definition Update
Role Assignment Add
Role Assignment Delete
Role Assignment Update
Break Inheritance
Reset Inheritance
41. WebHooks have a retry mechanism with an incremental back off
strategy (5 times with 5 minute interval)
WebHook calls are less taxing for your service endpoint
The WebHook payload is very small
Notifications are batched because processing depends on the CSOM GetChanges() call
WebHooks are more secure as no event information is passed
along during the notification
WebHooks are easier to consume by “non-SharePoint” developers
No WCF based endpoints, regular HTTP services are sufficient (e.g.
Web API)
42. WebHooks have an expiration date of maximum 6 months after
creation
You can “renew” a WebHook via a REST call
PATCH /_api/web/lists('list-id')/subscriptions('subscriptionID')
Two patterns are possible:
Have a background job that regularly renews the needed subscriptions (recommended model)
Renew at notification time (will drop WebHook if there’s no event within the defined expiration
window)
43. Connect remote debugger to your service and web job running
in Azure
Use ngrok (https://ngrok.com/) as alternative to create a tunnel
to your service running on localhost
49. Remote Event Receivers are here to stay
Use Webhooks if
Developing exclusively for SharePoint Online (currently)
Just need to handle list item events (currently)
Want to leverage automatic retries
Want to leverage increased security
Use Remote Event Receivers if
Targeting SharePoint On-Prem (2013 or later)
Need to handle events other than list item events
Use Server-side Event Receivers if
Targeting older versions of SharePoint (before 2013)