我的 WCF 数据服务遇到了问题。其中一个表包含太多要返回的数据(大约 80 个字段),因此只有一条记录会超过大小限制(估计超过 60k,我无法准确判断,因为无法看到消息消息输出中断)。
到目前为止,我发现它可以通过两种方式解决。
对于这两种解决方案,都有一些问题需要克服。
最佳答案
对于问题 #1,查看主题 Streaming Provider (WCF Data Services) ,其中包括此 WCF 配置,以使用 WCF 数据服务启用进出 OData 服务的大消息:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<!-- The name of the service -->
<service name="PhotoService.PhotoData">
<!--you can leave the address blank or specify your end point URI-->
<endpoint binding="webHttpBinding"
bindingConfiguration="higherMessageSize"
contract="System.Data.Services.IRequestHandler"></endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<!-- configure the maxReceivedMessageSize value to suit the max size of
the request (in bytes) you want the service to receive-->
<binding name="higherMessageSize" transferMode="Streamed"
maxReceivedMessageSize="2147483647"/>
</webHttpBinding>
</bindings>
对于问题#2,WCF 数据服务客户端不支持 JSON,只支持 Atom XML。你试过帖子Using System.Json for non-Silverlight projects?这似乎有一些关于从客户端数据服务解析 JSON 的其他替代方案的有用信息。
关于odata - 如何解决 WCF 数据服务中的默认消息大小限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5918749/