首页 / C# / c# – 为什么我会得到Soap异常?
c# – 为什么我会得到Soap异常?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 为什么我会得到Soap异常?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2066字,纯文字阅读大概需要3分钟。
内容图文
![c# – 为什么我会得到Soap异常?](/upload/InfoBanner/zyjiaocheng/771/7a50dd382964418e9d722d8b78276d97.jpg)
我正在尝试将附件上传到列表:
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);
}
}
}
}
我得到Unhandled 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.Try catch(SoapException ex)这是一种更好的方法
所以,专注于异常处理伙伴,
我希望这可以帮助你
问候
内容总结
以上是互联网集市为您收集整理的c# – 为什么我会得到Soap异常?全部内容,希望文章能够帮你解决c# – 为什么我会得到Soap异常?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。