WCF 上传大数据时 报错 读取 XML 数据时,超出最大数组长度配额(16384)

本文介绍如何通过修改 WCF 服务端配置实现大文件传输。主要涉及 system.serviceModel 下 bindings 节点的配置调整,包括设置超时时间、缓冲池大小等参数,并在 services 节点中引用配置。

修改服务端配置

服务器端没有

bindings 节点需要在system.serviceModel中增加



   <bindings>
      <basicHttpBinding>
        <binding name="LargeDataTransferServicesBinding" sendTimeout="00:10:00"
          maxBufferPoolSize="10485760" maxBufferSize="10485760" maxReceivedMessageSize="2147483647"
          transferMode="Streamed" messageEncoding="Text">
          <readerQuotas maxStringContentLength="10485760" maxArrayLength="10485760"
            maxBytesPerRead="10485760" />
        </binding>
      </basicHttpBinding>
    </bindings>

在bindingConfiguration 中填写 上边 binding 的name “LargeDataTransferServicesBinding”
    <services>
      <service name="WCFdome.wcfupfiles">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeDataTransferServicesBinding"
          contract="WCFdome.Iwcfupfiles" />
        <host>
          <timeouts openTimeout="00:10:00" />
        </host>
      </service>
    </services>

public static ISstService Api { get { try { ExeConfigurationFileMap map = new ExeConfigurationFileMap(); var AssemblyDirectory = DirFileHelper.GetAssemblyDirectory; map.ExeConfigFilename = AssemblyDirectory + "\\HY.Shell.18.2.exe.config"; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); //服务地址信息 var svcServiceAddress = config.AppSettings.Settings["SstServiceURL"].Value.ToString(); var ePo = new EndpointAddress(svcServiceAddress); var bHb = new BasicHttpBinding() { Security = { Mode = BasicHttpSecurityMode.None } }; bHb.Name = "BasicHttpBinding"; bHb.CloseTimeout = new TimeSpan(00, 59, 59); bHb.OpenTimeout = new TimeSpan(00, 59, 59); bHb.ReceiveTimeout = new TimeSpan(00, 59, 59); bHb.SendTimeout = new TimeSpan(00, 59, 59); bHb.AllowCookies = false; bHb.BypassProxyOnLocal = false; bHb.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; bHb.MaxBufferSize = 2147483646; bHb.MaxBufferPoolSize = 2147483646; bHb.MaxReceivedMessageSize = 2147483646; bHb.MessageEncoding = WSMessageEncoding.Text; bHb.TextEncoding = System.Text.Encoding.UTF8; bHb.TransferMode = TransferMode.Buffered; bHb.UseDefaultWebProxy = true; bHb.ReaderQuotas = new XmlDictionaryReaderQuotas() { MaxDepth = 32, MaxStringContentLength = 2147483646, MaxArrayLength = 2147483646, MaxBytesPerRead = 2147483646, MaxNameTableCharCount = 2147483646 }; var customersFactory = new ChannelFactory<ISstService>(bHb, ePo); var iService = customersFactory.CreateChannel(); return iService; } catch (Exception ex) { throw ex; } }
07-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值