c# – 为什么我会得到Soap异常?
发布时间:2020-12-15 22:01:03  所属栏目:百科  来源:网络整理 
            导读:我正在尝试将附件上传到列表: 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 Progra
                
                
                
            | 
                         
 我正在尝试将附件上传到列表: 
  
  
  
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,(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:XxxxlTestCConsoleApplication3ConsoleApplication3Web ReferencesServiceWebReferenceReference.cs:line 782
  at ConsoleApplication3.Program.Main(String[] args) 
    in z:XxxxlTestCConsoleApplication3ConsoleApplication3Program.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存在 所以,专注于异常处理伙伴, 问候 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
