gpt4 book ai didi

c# - 为什么我会得到 Soap 异常?

转载 作者:行者123 更新时间:2023-11-30 12:46:05 25 4
gpt4 key购买 nike

我正在尝试将附件上传到列表:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com