上传图片超过16kb vs2010 c#asp.net

时间:2011-08-29 12:13:33

标签: c# asp.net visual-studio-2010 upload

我想将大图片(超过16kb)上传到数据库。(我用小图片成功了) 我已经在它找到的所有地方将MaxArrayLength更改为2147483647(默认情况下为16384)。 但是我在debbuging之后仍然收到此错误消息:

格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数http://tempuri.org/:PicToAdd时出错。 InnerException消息是'反序列化BL.BE.Picture类型的对象时出错。读取XML数据时已超出最大数组长度配额(16384)。通过更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象上的MaxArrayLength属性,可以增加此配额。第1行,位置41545.'。有关更多详细信息,请参阅InnerException 源代码:

Line 218:        public string BLS_AddPicture(BL.BE.Picture PicToAdd) {
Line 219:            **return base.Channel.BLS_AddPicture(PicToAdd);**
Line 220:        }

我该怎么做才能尽快修复!!! 谢谢

1 个答案:

答案 0 :(得分:0)

您必须在WCF配置中更改XmlDictionaryReaderQuotas.MaxArrayLength设置。

您可以在配置文件中执行此操作:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding ...>
                <readerQuotas maxDepth="32" 
                              maxStringContentLength="8192"
                              maxArrayLength="16384"
                              maxBytesPerRead="4096" 
                              maxNameTableCharCount="16384" />

或代码:

XmlDictionaryReaderQuotas lOQuotas = new XmlDictionaryReaderQuotas()
           {
                    MaxArrayLength = Int32.MaxValue,
                    MaxBytesPerRead = Int32.MaxValue,
                    MaxDepth = Int32.MaxValue,
                    MaxNameTableCharCount = Int32.MaxValue,
                    MaxStringContentLength = Int32.MaxValue
           };

myBinding.ReaderQuotas = lOQuotas;