从C#代码创建SharePoint远程事件接收器

时间:2015-06-29 14:08:36

标签: c# wcf sharepoint sharepoint-2013 event-receiver

我有一个包含一些OOB列表(文档和任务)的sharepoint站点。 我想在我的程序中捕获列表更改。

我尝试通过CSOM为此服务创建WCF服务和远程事件接收器(RER),但WCF服务没有捕获任何消息。

WCF服务和RER是在简单的C#应用​​程序(控制台应用程序)中创建的。

WCF服务类

public class RemoteEventService : Microsoft.SharePoint.Client.EventReceivers.IRemoteEventService
{
    public void ProcessOneWayEvent(SPRemoteEventProperties properties)
    {
       // some code here
    }


    public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
    {
        SPRemoteEventResult result = null;
        ClientContext context = null;

        // some code here

        return result;
    }
}

WCF服务创建

    using (ServiceHost host = new ServiceHost(typeof(RemoteEventService)))
        {
            host.Open();
            host.Description.Behaviors.Find<ServiceAuthorizationBehavior>().ImpersonateCallerForAllOperations = true;
            Console.WriteLine("Started service at " + host.BaseAddresses[0].ToString());
            Console.WriteLine("Press <enter> to terminate  the Application");
            Console.ReadKey(true);
        }  

创建远程事件接收器

    // check that RER doesn't exist
    EventReceiverDefinitionCreationInformation receiverAdded =
                        new EventReceiverDefinitionCreationInformation();

    receiverAdded.EventType = EventReceiverType.ItemAdded;
    receiverAdded.ReceiverUrl = SERVICE_URL;
    receiverAdded.ReceiverName = "TestDocReceiverAdded";
    receiverAdded.Synchronization = EventReceiverSynchronization.Asynchronous;

    docList.EventReceivers.Add(receiverAdded);
    context.ExecuteQuery();

创建了RER(在下次运行我的应用程序时可以在调试检查中使用),但WCF服务没有捕获任何消息。

我已经检查过可以从托管Shapoint站点的网络获得WCF-serivce。 我不确定用户(用于连接到我的应用程序中的sharepoint)是否具有足够的权限来管理sharepoint OOB列表。

从NOT sharepoint-app添加RER到sharepoint OOB列表是否可行? 如果没有什么是在我的程序中捕获列表更改的最佳方法?

0 个答案:

没有答案