Sharepoint 2010的列表Web服务中的DeleteAttachment方法带有“Microsoft.SharePoint.SoapServer.SoapServerException”错误

时间:2014-03-10 18:25:05

标签: c# sharepoint sharepoint-2010

我有一个名为“Registrant”的文档库,在库中,注册人正在将文档上传到他们自己的文件夹中说“REGISTRANT1_GUIDofRegistrant1

目前情况为“http://registry.example.com/CRMDocuments/contact/

其中“CRMDocuments”是里面的文件夹。我有多个文档库,如注册人(联系人名称显示在URL中,因为“Registrant”是显示名称。)

我有一个门户网站,注册人可以在其中注册并登录:

http://registry.example.com/register.aspx

注册后,他们可以将文档上传到共享点,并将在Web门户中列出,并且可以根据需要删除文档。

在初始上传系统中,将以“REGISTRANT1_GUIDofRegistrant1”格式在“注册人”文档库中创建一个文件夹,所有文件都将存储在此文件夹中。

我正在使用share point 2010网络服务来创建文件夹和上传文档,从特定文件夹中获取项目列表并删除文件夹中的任何附件。

MSDN中的Web服务引用是:

msdn.microsoft.com/en-us/library/office/websvclists.lists.deleteattachment%28v=office.14%29.aspx

我正在为这些Web服务创建一个“服务参考”,用于创建文件夹,上传文档以及从特定文件夹中获取项目列表,但是删除不是。

我有代码参考:

    BasicHttpBinding bind = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
            BasicHttpSecurity security = new BasicHttpSecurity();
            HttpTransportSecurity http = new HttpTransportSecurity();
            http.ClientCredentialType = HttpClientCredentialType.Ntlm;

            security.Transport = http;
            security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
            bind.Security = security;

            SharePoint.List.ListsSoapClient client = new SharePoint.List.ListsSoapClient(bind, new EndpointAddress("http://registry.example.com/CRMDocuments/_vti_bin/Lists.asmx"));

             NetworkCredential cred = new NetworkCredential("UserID", "Password", "Domain");

            client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            client.ClientCredentials.Windows.ClientCredential = cred;


client.DeleteAttachment("Registrant", "516", "http://registry.example.com/CRMDocuments/contact/REGISTRANT1_b2ad3754-65a8-e311-befb-60a44cce3a94/sample1_Education.jpg");

这是一个错误:

"Exception of type
'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown"

使用堆栈跟踪:

Server stack trace:
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Registry.SharePoint.List.ListsSoap.DeleteAttachment(DeleteAttachmentRequest request)
   at Registry.SharePoint.List.ListsSoapClient.Registry.SharePoint.List.ListsSoap.DeleteAttachment(DeleteAttachmentRequest request) in c:\Dev\Solution\Lib\Service References\SharePoint.List\Reference.cs:line 2923
   at Registry.SharePoint.List.ListsSoapClient.DeleteAttachment(String listName, String listItemID, String url) in c:\Dev\PSW_Solution\PSWLib\Service References\SharePoint.List\Reference.cs:line 2932
   at Registry.PSWDocumentLocation.DeleteItemInDocumentLibrary(XrmServiceContext x, Entity entity, String sMOSSURL, NetworkCredential cred, String id, String url) in c:\Dev\Solution\Lib\DocumentLocation.cs:line 203

可以对这个问题有一些想法吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

我有一个解决方案

string batchId = "Batch123";
string id = "156"; //Document Id (NOT GUID)

                string strBatch = "<Batch OnError='Continue'><Method ID='" + batchId + "' Cmd='Delete'>" +
                           "<Field Name='ID'>" + id + "</Field>" +
                           "<Field Name='FileRef'>" + url + "</Field>" +
                          "</Method></Batch>";

                XDocument elBatch = XDocument.Parse(strBatch);
                XElement res = client.UpdateListItems("registrant", elBatch.Root);

这将完成这项工作。我知道这不是我问题的实际解决方案,但这肯定是一种解决方法。

Vinu