网站如何提交关键词,wordpress怎么开发文档,开源无代码开发平台,社交分享 wordpress开发中所用的数据需要通过WCF进行数据传输#xff0c;结果就遇到了WCF大量传输问题 也就是提示System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接
网上解决方案都是千篇一律互相转发的#xff0c;并且没有明确的解决方案或者按照#xff0c;各个博客中…开发中所用的数据需要通过WCF进行数据传输结果就遇到了WCF大量传输问题 也就是提示System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接
网上解决方案都是千篇一律互相转发的并且没有明确的解决方案或者按照各个博客中的解决方案都没能解决这个问题。
为此我整整浪费了一天时间用来解决这个问题而且用了最笨的办法一点点的尝试网上所查到的方案。对于精研WCF来说的这可能是一个小问题但是对于仅仅了解wcf一知半解的会很困惑。将解决方案贴出来希望能帮助到一样遇到此问题和没有深入研究过wcf的程序猿们快速解决这个问题. 首先网上所说的解决大数据量传输需要给修改客户端与服务端的配置属性 maxBufferPoolSize2147483647 maxBufferSize2147483647 maxReceivedMessageSize2147483647 单位是字节数最大为2G 服务端配置 bindings basicHttpBinding binding nameGEDemoServiceBinding closeTimeout00:05:00 openTimeout00:05:00 sendTimeout00:05:00maxBufferPoolSize2147483647 maxBufferSize2147483647 maxReceivedMessageSize2147483647 readerQuotas maxStringContentLength2147483647 maxArrayLength2147483647 maxBytesPerRead2147483647 maxNameTableCharCount2147483647 maxDepth32 / /binding /basicHttpBinding /bindings
客户端配置 bindings basicHttpBinding binding nameBasicHttpBinding_IGEDemoService closeTimeout00:01:00 openTimeout00:01:00 receiveTimeout00:10:00 sendTimeout00:01:00 allowCookiesfalse bypassProxyOnLocalfalse hostNameComparisonModeStrongWildcard maxBufferSize2147483647 maxBufferPoolSize2147483647 maxReceivedMessageSize2147483647 messageEncodingText textEncodingutf-8 transferModeBuffered useDefaultWebProxytrue readerQuotas maxDepth32 maxStringContentLength8192 maxArrayLength16384 maxBytesPerRead4096 maxNameTableCharCount16384 / security modeNone transport clientCredentialTypeNone proxyCredentialTypeNone realm / message clientCredentialTypeUserName algorithmSuiteDefault / /security /binding /basicHttpBinding /bindings 但是这远远不够这只是修改了wcf传输通道的空间容量。
但是由于WCF传输时肯定会涉及到自定义对象的传输因此服务端与客户端通过wcf传输时需要进行序列化因此需要修改dataContractSerializer配置属性 修改dataContractSerializer节点以后的配置
服务端配置 behavior nameGE_DemoService.GEDemoServiceBehavior serviceMetadata httpGetEnabledtrue / serviceDebug includeExceptionDetailInFaultstrue / dataContractSerializer maxItemsInObjectGraph2147483647/ /behavior 客户端配置 !--Service Configure-- endpoint addresshttp://localhost:10081/GEDemoService/ bindingbasicHttpBinding bindingConfigurationBasicHttpBinding_IGEDemoService contractDemoService.IGEDemoService nameBasicHttpBinding_IGEDemoService behaviorConfigurationendpoinmaxItemsInObjectGraph / /client behaviors
endpointBehaviors behavior nameendpoinmaxItemsInObjectGraph dataContractSerializer maxItemsInObjectGraph2147483647/ /behavior /endpointBehaviors
/behaviors 至此修改配置完成没怎么大批量测试但是解决我当时遇到的问题是可以了传输数据2000以上。没有问题了原来只要超过1000条数据则就会挂掉因此此方案是可行的
。
最后需要注意的是在客户端配置文件中增加httpRuntime配置节点
httpRuntime maxRequestLength512000 executionTimeout120 / 这是因为
如果WCF以IIS作为宿主WCF传输数据量的能力还受到HttpRunttime设置的制约可能需要修改HttpRunttime在system.Web节中的MaxRequestLength属性。MaxRequestLength属性表示请求的最大大小以千字节为单位。默认大小为 4096 KB (4 MB)允许的最大值是2097151。