我正在尝试将附件上传到列表中:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication3.TestReference;
using System.IO;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string srcUrl = @"C:......comp_name.xlsx";
FileStream fStream = File.OpenRead(srcUrl);
string fileName = fStream.Name.Substring(3);
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
ServiceWebReference.Lists listService = new ServiceWebReference.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
try
{
// adding attachment
string result = listService.AddAttachment("testList", "1", fileName, contents);
Console.WriteLine(result);
}
catch (System.Web.Services.Protocols.SoapException e)
{
Console.WriteLine(e.GetBaseException());
Console.WriteLine(e);
}
}
}
}
我遇到了未处理的SOAP异常...
以下是我收到的完整异常信息:
System.Web.Services.Protocols.SoapException: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at ConsoleApplication3.ServiceWebReference.Lists.AddAttachment(String listName, String listItemID, String fileName, Byte[] attachment)
in z:\Xxxxl\TestC\ConsoleApplication3\ConsoleApplication3\Web References\ServiceWebReference\Reference.cs:line 782
at ConsoleApplication3.Program.Main(String[] args)
in z:\Xxxxl\TestC\ConsoleApplication3\ConsoleApplication3\Program.cs:line 29
Press any key to continue . . .
我正确添加了引用:
http ..... /_vti_bin/lists.asmx
。我该如何进行调试?在我的情况下,SOAP异常是什么?
SoapException
。完整的异常信息是什么?请在你的问题中发布它。 - John SaundersSoapException
表示服务器返回了一个错误。它可能已经返回了一个“SOAP Fault”,其中可能包含了其他信息。你应该这样做:try {...你的代码...} catch (SoapException ex){...在这里你可以查看异常的详细信息...}
- John Saunderscatch (System.Web.Services.Protocols.SoapException ex)
- John SaundersConsole.WriteLine(e);
即可。您可能还想在Console.WriteLine
处设置断点,并在调试器中查看e
的内容。 - John Saunders