简体   繁体   English

WCF服务中的缓冲区大小

[英]Buffer size in WCF service

We have a WCF service which executes certain stored procedures and returns the results to the silverlight client. 我们有一个WCF服务,它执行某些存储过程并将结果返回给silverlight客户端。 Some of the stored procedures return upto 80K rows. 某些存储过程最多返回80K行。

Given below are the settings in web.config for Service 下面给出了web.config for Service中的设置

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <behaviors>
       <serviceBehaviors>
           <behavior name="MyService.MyServiceBehavior">
               <serviceMetadata httpGetEnabled="true"/>
               <serviceDebug includeExceptionDetailInFaults="true"/>
               <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
           </behavior>
       </serviceBehaviors>
    </behaviors>
    <bindings>
       <basicHttpBinding>
           <binding name="BasicHttpBinding_MyService" 
                maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" 
                receiveTimeout="00:40:00" openTimeout="00:40:00" 
                closeTimeout="00:40:00" sendTimeout="00:40:00">
                <readerQuotas maxDepth="2147483647" 
                    maxStringContentLength="2147483647" maxArrayLength="2147483647" 
                    maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                <security mode="None"/>
           </binding>
        </basicHttpBinding>
        <customBinding>
           <binding name="MyService.MyService.customBinding0">
              <binaryMessageEncoding/>
              <httpTransport/>
            </binding>
        </customBinding>
     </bindings>
     <services>
          <service behaviorConfiguration="MyService.MyServiceBehavior" 
                   name="MyService.MyService">
              <endpoint name="BasicHttpBinding_MyService" 
                  address="" 
                  binding="basicHttpBinding" 
                  bindingConfiguration="BasicHttpBinding_MyService" 
                  contract="MyService.IMyService"/>
           </service>
     </services>
</system.serviceModel>

And this for Client 这对客户而言

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
    <behaviors>
       <serviceBehaviors>
           <behavior name="MyService_Behavior">
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <serviceMetadata httpGetEnabled="true"/>
           </behavior>
       </serviceBehaviors>
       <endpointBehaviors>
          <behavior name="r1">
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
          </behavior>
       </endpointBehaviors>
    </behaviors>
    <bindings>
       <basicHttpBinding>
            <binding name="BasicHttpBinding_MyService" 
                closeTimeout="00:03:00" openTimeout="00:03:00" 
                receiveTimeout="00:10:00" sendTimeout="00:03:00" 
                allowCookies="false" bypassProxyOnLocal="false" 
                hostNameComparisonMode="StrongWildcard" 
                maxBufferSize="2147483647" maxBufferPoolSize="2147483647" 
                maxReceivedMessageSize="2147483647" 
                messageEncoding="Text" textEncoding="utf-8" 
                transferMode="Buffered" useDefaultWebProxy="true">
               <security mode="None"/>
             </binding>
        </basicHttpBinding>
     </bindings>
     <client>
        <endpoint name="BasicHttpBinding_MyService"
            address="http://localhost:8080/MyService/MyService.svc" 
            behaviorConfiguration="r1"
            binding="basicHttpBinding" 
            bindingConfiguration="BasicHttpBinding_MyService" 
            contract="MyService.IMyService"  />
    </client>
</system.serviceModel>

Whenever the number of records go beyond 20K, the service throws an error as either TimeOut or NotFound. 只要记录数超过20K,服务就会抛出一个错误,如TimeOut或NotFound。 Why do you think this happens n how do I fix it? 为什么你认为这会发生?我该如何解决?

It sounds like sheer data overload. 这听起来像纯粹的数据过载。 Pagination, as noted in comments, is a practical solution. 如评论中所述,分页是一种实用的解决方案。 If there is a good reason to want the 80k, you could try using a different mechanism to serialize the data. 如果有充分的理由想要80k,您可以尝试使用不同的机制来序列化数据。 For example, protobuf data is generally much smaller than xml, so you might try using that on the wire. 例如,protobuf数据通常小于xml,因此您可以尝试在线上使用它。 However, since this is Silverlight I can't (currently) swap this automatically - you would need to return a byte[] or Stream and handle the serialization/deserialization explicitly at the server/client. 但是,由于这是Silverlight,我无法(当前)自动交换 - 您需要返回byte[]Stream并在服务器/客户端显式处理序列化/反序列化。 This should drop the bandwidth requirements by a fair whack (even more if you can configure Silverlight to use MTOM - I haven't checked lately, but this wasn't supported in some earlier releases). 这应该会减少带宽需求(如果您可以将Silverlight配置为使用MTOM,则更多 - 我最近没有检查过,但在某些早期版本中不支持这种情况)。

As your proc returns 80K, you have to add your buffer size at Client end as well. 当您的proc返回80K时,您还必须在客户端添加缓冲区大小。

readerQuotas readerQuotas

<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>

This should work. 这应该工作。 If required increase your buffer size. 如果需要,请增加缓冲区大小。

We have successfully used GZIP compression between the Client and the WCF service to increase the number of rows we could pull back. 我们已成功在客户端和WCF服务之间使用GZIP压缩,以增加我们可以撤回的行数。 Should also work for your needs. 也应该适合您的需求。

We used the MS libraries to achieve it: http://msdn.microsoft.com/en-us/library/ms751458.aspx 我们使用MS库来实现它: http//msdn.microsoft.com/en-us/library/ms751458.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM