我用wcf返回二维数组,经测试在超过1500行数据时,就会抛出“基础连接已经关闭: 连接被意外关闭”的异常信息。经测试该返回值长度22M左右,但是我用DataSet作为结果返回到33M都没有问题。请问有谁知道其中的原因吗?我的配置文件是: <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="LoaderServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:9001/" />
        </behavior>
        <behavior name="NewBehavior">
          <serviceMetadata httpGetEnabled="false"/>
          <serviceTimeouts transactionTimeout="00:03:00" />
          <dataContractSerializer maxItemsInObjectGraph="65536000" />
        </behavior>
      </serviceBehaviors>    </behaviors>
    <bindings>
      <wsDualHttpBinding>
        <binding name="LoaderDualHttpBindingConfig" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          <security mode="None"></security>
        </binding>
      </wsDualHttpBinding>      <basicHttpBinding>
        <binding name="LoaderHttpBindingConfig"  maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
                    maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                     maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="" name="IisServer.MyServer">
       <!-- <endpoint  binding="wsDualHttpBinding"
            bindingConfiguration="LoaderDualHttpBindingConfig" name="IisServer.MyServer"
            contract="contract.IContract" />-->
        
        <endpoint  binding="basicHttpBinding"
    bindingConfiguration="LoaderHttpBindingConfig" name="IisServer.MyServer"
    contract="contract.IContract" />
      </service>
    </services>
  </system.serviceModel>

解决方案 »

  1.   

    大容量数据传输,web.config修改方法
    增加   <httpRuntime executionTimeout="900" maxRequestLength="102400" useFullyQualifiedRedirectUrl="false" />
    这样试试
      

  2.   

    By default WCF only allows small messages and arrays to be processed The first thing you will probably notice is that when trying to send a large file the connection will just close or return some strange error. This is due to the fact that either the message will timeout or exceed the maxReceivedMessageSize for the binding. This can be modified by adding a binding configuration that sets the send/receive timeouts and the message size.<bindings> 
      <wsHttpBinding> 
        <binding name="FileTransferBinding" 
        closeTimeout="00:01:00" 
        openTimeout="00:01:00" 
        receiveTimeout="00:10:00" 
        sendTimeout="00:01:00" 
        maxReceivedMessageSize="73400320" > <!--70MB--> 
              <readerQuotas maxArrayLength="73400320" /> 
        </binding> 
      </wsHttpBinding> 
    </bindings> 
    WCF also has default limits on the maximum size of an array so I set the maxArrayLength option on the binding to be quite large.Next all you have to do is set the endpoints binding configuration to be the configuration we just created:<endpoint address=""  
                  binding="wsHttpBinding"  
                  bindingConfiguration="FileTransferBinding" 
                  contract="MyProj.IService" /> 
    Now one thing that I would recommend would be to use a binary binding like netTCP instead of a HTTP based binding for a case like this. Unfortunately if you are hosting your service in IIS6 you can only use HTTP based bindings (in IIS7 you can use TCP based bindings in addition to HTTP). Also if you are hosting your service in IIS you will need to adjust the httpRuntime to allow large files as well. This can be done in the <system.web> section like so: <httpRuntime maxRequestLength="73400" />  For the sake of completeness here is my completed <system.serviceModel> section: <system.serviceModel> 
      <services> 
        <service name="MyApp.Service.FileProcessor"  
                    behaviorConfiguration="MyApp.Service.FileProcessorBehavior"> 
          <endpoint address="" 
                        binding="wsHttpBinding"  
                        bindingConfiguration="FileTransferServicesBinding" 
                        contract="MyApp.Service.IFileProcessor" /> 
          <endpoint address="mex" 
                        binding="mexHttpBinding"  
                        contract="IMetadataExchange"/> 
        </service> 
      </services> 
      
      <behaviors> 
        <serviceBehaviors> 
          <behavior name="MyApp.Service.FileProcessorBehavior"> 
            <serviceMetadata httpGetEnabled="true"/> 
            <serviceDebug includeExceptionDetailInFaults="true"/> 
          </behavior> 
        </serviceBehaviors> 
      </behaviors>   <bindings> 
        <wsHttpBinding> 
          <binding name="FileTransferServicesBinding" 
                      closeTimeout="00:01:00" 
                      openTimeout="00:01:00" 
                      receiveTimeout="00:10:00" 
                      sendTimeout="00:01:00" 
                      maxReceivedMessageSize="73400320" >  
            <readerQuotas maxArrayLength="73400320" /> 
          </binding> 
        </wsHttpBinding> 
      </bindings> </system.serviceModel> 
     Now as with everything there is more than one way to toss a cat off a bridge. One thing to add to this would be compression to shrink the data being transferred (if the data you are transferring compresses well at least). WCF has support for streaming data instead of our current buffer approach. Our services code will not kick in until we have received all of the data. If we used a stream approach we could start processing data as it arrives.   
      

  3.   

    主要就是修改maxReceivedMessageSize、maxArrayLength,如果是在IIS里面host,那么需要同时修改web.config里面的
    <httpRuntime maxRequestLength="73400" /> 
      

  4.   

    楼主,你是怎样让wcf返回数组的?