/// <summary> /// Responds to requests generated by subscriptions registered with /// the SharePoint WebHook REST API. /// </summary> /// <param name="validationToken">The validation token (guid) sent by SharePoint when /// validating the Notification URL for the web hook subscription.</param> public async Task <HttpResponseMessage> Post(string validationToken = null) { // If a validation token is present, we need to respond within 5 seconds by // returning the given validation token. This only happens when a new // web hook is being added if (validationToken != null) { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(validationToken); return(response); } // Read and parse the request body. var content = await Request.Content.ReadAsStringAsync(); var notifications = JsonConvert.DeserializeObject <ResponseModel <NotificationModel> >(content).Value; if (notifications.Count > 0) { // do something with the received notification ChangeManager changeManager = new ChangeManager(); foreach (var notification in notifications) { // Recommended async pattern: this request must be processed within 5 seconds, // hence it's better to do the processing using an asynchronous pattern. changeManager.AddNotificationToQueue(CloudConfigurationManager.GetSetting("StorageConnectionString"), notification); // Synchronous pattern: only for very simple operations that always complete within 5 seconds! //changeManager.ProcessNotification(notification); } } // if we get here we assume the request was well received return(new HttpResponseMessage(HttpStatusCode.OK)); }