Kev*_*Kev 6 c# silverlight wcf
我们有一个WCF服务,它执行某些存储过程并将结果返回给silverlight客户端.某些存储过程最多返回80K行.
下面给出了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>
Run Code Online (Sandbox Code Playgroud)
这对客户而言
<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>
Run Code Online (Sandbox Code Playgroud)
只要记录数超过20K,服务就会抛出一个错误,如TimeOut或NotFound.为什么你认为这会发生?我该如何解决?
听起来像是纯粹的数据过载。正如评论中所述,分页是一种实用的解决方案。如果有充分的理由需要 80k,您可以尝试使用不同的机制来序列化数据。例如,protobuf 数据通常比 xml小得多,因此您可以尝试在线使用它。但是,由于这是 Silverlight,我(当前)无法自动交换它 - 您需要返回一个byte[]orStream并在服务器/客户端显式处理序列化/反序列化。这应该会大大降低带宽要求(如果您可以将 Silverlight 配置为使用 MTOM,则带宽要求会更低 - 我最近没有检查过,但在某些早期版本中不支持这一点)。