gpt4 book ai didi

c# - WCF 服务中的缓冲区大小

转载 作者:太空狗 更新时间:2023-10-29 21:36:23 25 4
gpt4 key购买 nike

我们有一个 WCF 服务,它执行某些存储过程并将结果返回给 silverlight 客户端。一些存储过程返回多达 80K 行。

下面给出了服务的 web.config 中的设置

<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>

这是给客户的

<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>

只要记录数超过 20K,服务就会抛出 TimeOut 或 NotFound 错误。您认为为什么会发生这种情况,我该如何解决?

最佳答案

这听起来像是纯粹的数据过载。如评论中所述,分页是一种实用的解决方案。如果有充分的理由需要 80k,您可以尝试使用不同的机制来序列化数据。例如,protobuf 数据通常 小于 xml,因此您可以尝试在线使用它。但是,由于这是 Silverlight,我不能(目前)自动交换它 - 您需要返回一个 byte[]Stream 并显式处理序列化/反序列化服务器/客户端。这应该会大大降低带宽要求(如果您可以将 Silverlight 配置为使用 MTOM 甚至更多 - 我最近没有检查过,但某些早期版本不支持这一点)。

关于c# - WCF 服务中的缓冲区大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5337412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com