作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将附件上传到列表:
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 异常是什么?
最佳答案
为什么要使用 catch (System.Web.Services.Protocols.SoapException e)
1.用ex代替e,因为e已经作为EventArgs e
存在2.尝试catch (SoapException ex)
这是一个更好的方法
所以,集中精力处理异常,希望对你有帮助
关于c# - 为什么我会得到 Soap 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21517230/
我是一名优秀的程序员,十分优秀!