Remote Event Receiver is not being triggered

I have a list called clients, when a new item is added to the list a new sub site should be created.
I created an Azure Service Bus and copy pasted the ACS connection string for debugging.

I can debug the App Installed event without any problems, however when a new item is added to the list breakpoints are never hit.

I checked on Sharepoint Client Browser and the remote event receiver is there.
screencast.com/t/OoPDhqRq

The code to add the RER and to execute the item added is here:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.EventReceivers;
using Capatech.IntranetWeb.Provisioning;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace xx.IntranetWeb.Services
{
public class AppEventReceiver : IRemoteEventService
{
///

/// Handles app events that occur after the app is installed or upgraded, or when app is being uninstalled.
///

/// Holds information about the app event. /// Holds information returned from the app event.
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
{
SPRemoteEventResult result = new SPRemoteEventResult();
try
{
switch (properties.EventType)
{
case SPRemoteEventType.AppInstalled:
AppEvents.AppInstalled(properties);
result.Status = SPRemoteEventServiceStatus.Continue;
break;
case SPRemoteEventType.AppUninstalling:
//this.HandleAppUnInstall(properties);
result.Status = SPRemoteEventServiceStatus.Continue;
break;
case SPRemoteEventType.AppUpgraded:
AppEvents.AppUpgraded(properties);
result.Status = SPRemoteEventServiceStatus.Continue;
break;

}
return result;
}
catch (Exception ex)
{
//Log message
result.ErrorMessage = “Capatech.Intranet: ” + ex.Message;
result.Status = SPRemoteEventServiceStatus.CancelWithError;
return result;
}
}

///

/// To handle list events
///

/// public void ProcessOneWayEvent(SPRemoteEventProperties properties)
{
//Remote event receivers for clients
if (properties.ListEventProperties.ListTitle == “Clientes”)
{
switch (properties.EventType)
{
case SPRemoteEventType.ItemAdded:
Clients.HandleItemClientAdded(properties);
break;
case SPRemoteEventType.ItemUpdated:
Clients.HandleItemClientAdded(properties);
break;
}
}
}

}
}

{
const string CLIENTES_ITEMADDED = “CLIENTES_ITEMADDED”;
const string CLIENTES_ITEMUPDATED = “CLIENTES_ITEMUPDATED”;

///

/// Associate RER to client list.
///

/// Client context public static void AssociateItemAddedEventReceiverToClientList(ClientContext clientcontext)
{
List clientList = clientcontext.Web.Lists.GetByTitle(“Clientes”);
clientcontext.Load(clientList);

var eventReceivers = clientList.EventReceivers;
clientcontext.Load(eventReceivers);

clientcontext.ExecuteQuery();

var rerExists = false;

foreach (var rer in clientList.EventReceivers)
{
if (rer.ReceiverName == CLIENTES_ITEMADDED)
{
rerExists = true;
System.Diagnostics.Trace.WriteLine(“Found existing ItemAdded receiver at ” + rer.ReceiverUrl);
}
}

if (!rerExists)
{
EventReceiverDefinitionCreationInformation receiver = new EventReceiverDefinitionCreationInformation();
receiver.EventType = EventReceiverType.ItemAdded;
//receiver.Synchronization = EventReceiverSynchronization.Synchronous;
//Get WCF URL where this message was handled
OperationContext op = OperationContext.Current;
Message msg = op.RequestContext.RequestMessage;

receiver.ReceiverUrl = msg.Headers.To.ToString();
receiver.ReceiverName = CLIENTES_ITEMADDED;
//Add the new event receiver to a list in the host web

clientList.EventReceivers.Add(receiver);

clientcontext.ExecuteQuery();
}
}

///

/// This method is executed when a new client is added to the list
///

/// Remote vent properties public static void HandleItemClientAdded(SPRemoteEventProperties properties)
{
using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
{
if (clientContext != null)
{
CreateClientSiteAndUpdateSiteOnList(properties, clientContext);
}
}
}

///

/// Method to create a client site
///

/// Remote event properties /// Client Context private static void CreateClientSiteAndUpdateSiteOnList(SPRemoteEventProperties properties, ClientContext clientContext)
{
List requestList = clientContext.Web.Lists.GetById(properties.ItemEventProperties.ListId);
ListItem item = requestList.GetItemById(properties.ItemEventProperties.ListItemId);
clientContext.Load(item);
clientContext.ExecuteQuery();

string site_title = item[“NIT”].ToString() + ” ” + item[“Nombre Cliente”].ToString();
string site_url = item[“NIT”].ToString();

Web newWeb = clientContext.Web.CreateWeb(site_title, site_url, site_title, “STS#0″, 1033);
clientContext.Load(newWeb);
clientContext.ExecuteQuery();

//Updates site on the client list
FieldUrlValue siteUrl = new FieldUrlValue();
siteUrl.Url = newWeb.Url;
siteUrl.Description = site_title + ” Sitio”;
item[“Sitio Cliente”] = siteUrl;
item.Update();
clientContext.ExecuteQuery();
}

///

/// Configure properties on the client fields
///

/// Client context public static void ConfigureClientFields(ClientContext ctx)
{
List clientList = ctx.Web.Lists.GetByTitle(“Clientes”);
ctx.Load(clientList);
ctx.ExecuteQuery();

clientList.Fields.GetByInternalNameOrTitle(“Sitio Cliente”).SetShowInNewForm(false);
clientList.Fields.GetByInternalNameOrTitle(“Version Sitio”).SetShowInEditForm(false);
ctx.ExecuteQuery();
}

///

/// This method is executed when a client info is updated
///

/// Remote event properties public static void HandleItemClientUpdated(SPRemoteEventProperties properties)
{

}
}

=================

=================

1 Answer
1

=================

I fixed it by moving the ItemAdded code from ProcessOneWayEvent to ProcessEvent and that’s it.