Spca2014 debugging remote event receivers van hunen

Preview:

Citation preview

Debugging Remote Event Receivers

#SPCon14

@ME

• 20 years of industry experience

• Both Dutch and Swedish nationality

• Living in Stockholm, Sweden

• MCSM, MCM, MCT, MCSE, MCSD, MCSA, MCPD, MCITP, MCTS certifications

• Knowit AB

erwin.van.hunen@knowit.se

@erwinvanhunen

se.linkedin.com/in/erwinvanhunen

HANDS UP!

Who is using event receivers today?

ACS

Users

External System

Custom Web Service

SharePoint

1. User updates SharePoint list

3. Registered event receiver called

2. SharePoint requests a token from ACS

4. Line of business system is updated

5. Event receiver returns

https://github.com/OfficeDev/PnP/blob/master/Documentation/O365DevPnP%20-%20Site%20Provisioning.pptx

ACS

Users

External System

Custom Web Service

SharePoint

1. User updates SharePoint list

3. Registered event receiver called

2. SharePoint requests a token from ACS

4. Line of business system is updated

6. Event receiver calls back into SharePoint

5. Event receiver requests a token from ACS

https://github.com/OfficeDev/PnP/blob/master/Documentation/O365DevPnP%20-%20Site%20Provisioning.pptx

A BIT OF THEORY

ASYNCHRONOUS SYNCHRONOUS

• ‘Before’ events

• ItemAdding

• ItemUpdating

• ItemDeleting

• ‘After’ events

• ItemAdded

• ItemUpdated

• ItemDeleted

SYNCHRONOUS EVENTS

CAN BE CANCELLED

NOT FOR LONG

RUNNING TASKS

• Cancel with no error

• Cancel with error

• Cancel with redirect

ASYNCHRONOUS EVENTS

CANNOT BE CANCELLED

NOT FOR LONG

RUNNING TASKS

• At least not with a way to inform the user

EVENTS

ItemAddingItemUpdatingItemDeletingItemCheckingInItemCheckingOutItemUncheckingOutItemAttachmentAddingItemAttachmentDeletingItemFileMovingItemVersionDeleting

FieldAddingFieldUpdatingFieldDeletingListAddingListDeletingSiteDeletingWebDeletingWebMovingWebAddingGroupAddingGroupUpdatingGroupDeletingGroupUserAddingGroupUserDeletingRoleDefinitionAddingRoleDefinitionUpdatingRoleDefinitionDeleting

RoleAssignmentAddingRoleAssignmentDeletingInheritanceBreakingInheritanceResettingItemAddedItemUpdatedItemDeletedItemCheckedInItemCheckedOutItemUncheckedOutItemAttachmentAddedItemAttachmentDeletedItemFileMovedItemFileConvertedItemVersionDeletedFieldAddedFieldUpdatedFieldDeletedListAddedListDeletedSiteDeletedWebDeleted

WebMovedWebProvisionedWebRestoredGroupAddedGroupUpdatedGroupDeletedGroupUserAddedGroupUserDeletedRoleDefinitionAddedRoleDefinitionUpdatedRoleDefinitionDeletedRoleAssignmentAddedRoleAssignmentDeletedInheritanceBrokenInheritanceResetEntityInstanceAddedEntityInstanceUpdatedEntityInstanceDeletedAppInstalledAppUpgradedAppUninstalling

APP EVENTS APPINSTALLED APPUPGRADED APPUNINSTALLING

• Executed when the app is installed in a site

• Caveat: when using push installations the event will only run once!

• Executed when the user decides to upgrade the app

• Executed when the user decides to uninstall the app

• While debugging, make sure that the webservice/app is up and running

GOOD TO KNOW!

Events might be called several times

App events need to respond within a certain timeout. If no answer, the server will retry.

You have to handle that in your code, e.g. keep state, check if artifacts already exist before trying to create them, etc.

DEMO SITE MODIFIER

PATTERNAPP

INSTALLATION PATTERN

APP INSTALLATION PATTERN

APP HANDLES APPINSTALLED

EVENT

APP REGISTERS

ADDITIONAL EVEN

RECEIVERS

SAME WEBSERVICE

THAT HANDLES ALL

EVENTS

DEMO APP INSTALLATION PATTERN

CAVEAT

Custom events registered through the object model that do not reside in an app will not receive a context

• Create an App Only context

DEBUGGING

SharePoint Online

LIST Developer Machine

https://tenant.sharepoint.com https://localhost:44300

XAzureServiceBus

Azure ServiceBus

LOCALHOST

EVENT RECEIVER URLS ARE BEING

REPLACED DURING

DEPLOYMENT

• Localhost is a different server to SharePoint Online

• Make sure to disable the usage of Azure ServiceBus to debug when going live.

Azure ServiceBus

ACS AUTHENTICATION

NEEDED

ONLY DEFAULT ON SB

INSTANCES CREATED

BEFORE AUGUST 2014

Create new Azure SB instance:

New-AzureSPNamespace –Name <yoursbname>–Location “<location>” –CreateACSNamespace

Location = Northern Europe, Western Europe etc.

https://github.com/officedev/pnp

CMDLETS

Get-SPOEventReceiver

[-List [<ListPipeBind>]]

[-Identity [<GuidPipeBind>]]

[-Web [<WebPipeBind>]]

CMDLETS

Add-SPOEventReceiver

-List [<ListPipeBind>]

-Name [<String>] -Url [<String>]

-EventReceiverType [<EventReceiverType>]

-Synchronization [<EventReceiverSynchronization>]

[-SequenceNumber [<Int32>]]

[-Force [<SwitchParameter>]]

[-Web [<WebPipeBind>]]

CMDLETS

Remove-SPOEventReceiver

[-List [<ListPipeBind>]]

-Identity [<GuidPipeBind>]

[-Force [<SwitchParameter>]]

[-Web [<WebPipeBind>]]

Recommended