使用wcf服务传输大量数据

时间:2012-12-04 16:21:42

标签: asp.net wcf maxstringcontentlength

当我尝试在WCF中传输大数据时,我收到此错误:

  

格式化程序在尝试反序列化时抛出异常   消息:尝试反序列化参数时出错   http://tempuri.org/:requete。 InnerException消息是'有的   反序列化System.String类型的对象时出错。最大值   读取XML时已超出字符串内容长度配额(8192)   数据。可以通过更改此配额来增加此配额   XmlDictionaryReaderQuotas上的MaxStringContentLength属性   创建XML阅读器时使用的对象。第1行,位置8843.'。   有关更多详细信息,请参阅InnerException。

这是我的app.config文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="NewBinding0" maxBufferSize="52428800" maxBufferPoolSize="52428800">
          <readerQuotas maxStringContentLength="52428800" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="TSO_WCF.Service1">
        <host>
           <baseAddresses>
               <add baseAddress="http://localhost:8732/Design_Time_Addresses/TSO_WCF/Service1/" />
           </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="wsHttpBinding" contract="TSO_WCF.IService1" >
           <identity>
              <dns value="localhost"/>
           </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
       <serviceBehaviors>
          <behavior>
             <serviceMetadata httpGetEnabled="True"/>
             <serviceDebug includeExceptionDetailInFaults="False" />
          </behavior>
       </serviceBehaviors>
    </behaviors>
</system.serviceModel>
<appSettings>
   <add key="Mapping" value="D:\workspace\oddo.app.ldw.tsomanagertool\ProjetTSO\MappingsXML"/>
</appSettings>
</configuration>

2 个答案:

答案 0 :(得分:3)

您应该在服务器和客户端绑定上增加MaxStringContentLength。此时您使用的默认值为8192。

答案 1 :(得分:0)

也许您可以更改绑定/使用流式传输。查看此页面:http://msdn.microsoft.com/en-us/library/ms733742.aspx

相关问题