我有一个 SharePoint 2010 事件接收器,用于侦听 SharePoint 列表上的添加/更新/删除事件。当事件发生时,用 C# 编写的事件接收器需要将这些事件传递给 Java 程序。我的代码发布在下面。我可以很好地部署接收器并且它可以工作。我得到了我需要的所有 SharePoint 事件。现在我的问题是将这些事件传递给 Java。每次我尝试打开套接字或将 SharePoint 事件写入文件时都会出现安全异常。例如,查看我在下面发布的 ItemDeleting 方法,该方法在每次从 SharePoint 列表中删除项目时触发。当我尝试打开 Java 套接字时,我得到 System.Net.DnsPermission 异常。如果我不打开套接字并尝试写入文件,则会收到 System.Security.Permissions.FileIOPermission 异常。
我环顾了论坛,并尝试了一些方法来解决它。首先,我在 SharePoint 的 web.xml 中设置了 trust level="Full"。然后我设置了我的程序集的 DeploymentTarget="GlobalAssemblyCache"。这没有帮助。我还可以做些什么?预先感谢您的回复。
我的事件接收器代码:
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
using System.Net.Sockets;
using System.IO;
namespace EventReceiverTest
{
public class EventReceiver1 : SPItemEventReceiver
{
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
}
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
}
public override void ItemDeleting(SPItemEventProperties properties)
{
//can't open a socket connection.Request for the permission of type 'System.Net.DnsPermission,... failed
TcpClient tc = new TcpClient("192.168.xxx.xxx", xxx);
Console.WriteLine("Server invoked");
NetworkStream ns = tc.GetStream();
StreamWriter sw = new StreamWriter(ns);
sw.WriteLine("item deleted");
sw.Flush();
StreamReader sr = new StreamReader(ns);
Console.WriteLine(sr.ReadLine());
//can't write to file. Request for the permission of type 'System.Security.Permissions.FileIOPermission,...failed
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\logs\\test.txt");
file.WriteLine("item deleted " + properties.ListItem);
//can't output anything to a console
Console.Out.WriteLine("deleting an item ");
base.ItemDeleting(properties);
//but this part works
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "Deleting items from " + properties.RelativeWebUrl + " is not supported.";
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
<Properties>
<Property Key="GloballyAvailable" Value="true" />
</Properties>
</Feature>
<?xml version="1.0" encoding="utf-8"?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/">
<Assemblies>
<Assembly Location="EventReceiver3.dll" DeploymentTarget="GlobalAssemblyCache" />
</Assemblies>
<FeatureManifests>
<FeatureManifest Location="EventReceiver3_Feature1\Feature.xml" />
</FeatureManifests>
</Solution>