惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
博客园 - 叶小钗
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
博客园_首页
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 三生石上(FineUI控件)
Help Net Security
Help Net Security
Cloudbric
Cloudbric
AI
AI
N
News | PayPal Newsroom
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
Forbes - Security
Forbes - Security
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
SecWiki News
SecWiki News
H
Heimdal Security Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
S
Security @ Cisco Blogs
Google DeepMind News
Google DeepMind News
V
V2EX
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
S
Security Affairs
L
LangChain Blog
The Hacker News
The Hacker News
F
Full Disclosure
aimingoo的专栏
aimingoo的专栏
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
Webroot Blog
Webroot Blog
A
About on SuperTechFans
H
Hacker News: Front Page
Cyberwarzone
Cyberwarzone
WordPress大学
WordPress大学
L
LINUX DO - 热门话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Attack and Defense Labs
Attack and Defense Labs
M
MIT News - Artificial intelligence

博客园 - 同一片海

Win10 资源管理器窗口无边框的问题 Android Studio发布Release版本之坑--Unknown host 'd29vzk4ow07wi7.cloudfront.net' 浏览器外部署Silverlight更新检查失败的原因及对策 C#调用非托管Dll时的参数传递 使用ATL开发ActiveX控件 Silverlight自定义主题 在Silverlight 3中使用主题 [Silverlight]Selector类到底有没有SelectedValue属性? WCF安全之ASP.NET兼容模式 WCF安全之customBinding [Silverlight]AutoCompleteBox控件的一个Bug? [Silverlight]一个简单的GroupBox控件 [Silverlight]DataGrid相关的几个小知识点 实现下拉列表支持DataGrid的AutoCompleteBox 可分片数据持久层-ShardingPL使用说明 Silverlight数据绑定中的可空类型与自定义转换器 一个丑陋的对Silverlight中的Grid无CellPadding的解决方案 Silverlight中的资源文件 - 同一片海 - 博客园 【分享】SqlServer数据库文档生成工具
大数据量传输时配置WCF的注意事项
同一片海 · 2010-09-02 · via 博客园 - 同一片海

WCF传输数据量的能力受到许多因素的制约,如果程序中出现因需要传输的数据量较大而导致调用WCF服务失败的问题,应注意以下配置:

1、MaxReceivedMessageSize:获取或设置配置了此绑定的通道上可以接收的消息的最大大小。

basicHttpBinding等预定义的绑定一般具有MaxReceivedMessageSize属性,CustomBinding则需要在Transport中定义。

示例代码:

<bindings>
  <customBinding>
    <binding name="customBinding">
      <binaryMessageEncoding>
      </binaryMessageEncoding>
      <httpTransport maxReceivedMessageSize="2147483647">
      </httpTransport>
    </binding>
  </customBinding>
  <basicHttpBinding>
    <binding name="basicBinding" maxReceivedMessageSize="2147483647"></binding>
  </basicHttpBinding>
</bindings>

网上许多地方说应同时设置MaxBufferSize(获取或设置缓冲区的最大大小,该缓冲区用于接收来自通道的消息。),根据MSDN上的解释:

“MaxBufferSize 属性的值及其重要性有所不同,这取决于是否在接收消息的通道上对消息进行缓冲或流处理:

可见,对于默认的缓冲传输,设置该属性是不必要的。

2、ReaderQuotas:获取或设置可由配置了此绑定的终结点处理的 SOAP 消息的复杂性约束。

该属性是XmlDictionaryReaderQuotasElement类型,一般需要设置该属性的MaxArrayLengthMaxStringContentLengthMaxDepth属性。

示例代码:

<bindings>
  <customBinding>
    <binding name="customBinding">
      <binaryMessageEncoding>
        <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="64"/>
      </binaryMessageEncoding>
      <httpTransport maxReceivedMessageSize="2147483647">
      </httpTransport>
    </binding>
  </customBinding>
  <basicHttpBinding>
    <binding name="basicBinding" maxReceivedMessageSize="2147483647">
      <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="64"/>
    </binding>
  </basicHttpBinding>
</bindings>

3、MaxItemsInObjectGraph:获取对象图中要序列化或反序列化的最大项数。

该属性属于DataContractSerializer类,需要在serviceBehaviors下的behavior节中配置。

示例代码:

<behaviors>
  <serviceBehaviors>
    <behavior name="Wcf4BigData.Web.BigDataServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

以上是传输大数据量时可能需要设置的属于WCF的几个属性,示例代码中大多将属性值设置为允许的最大值,但设置后并不能保证WCF一定具有传输如此大数据量的能力。另外,这些属性一般需要在服务端和客户端同时设置,但如果使用Silverlight客户端,部分属性如ReaderQuotas并不被支持。

4、MaxRequestLength:获取或设置请求的最大大小。

如果WCF以IIS作为宿主,WCF传输数据量的能力还受到HttpRunttime设置的制约,可能需要同时HttpRunttime(在system.Web节中)的MaxRequestLength属性。MaxRequestLength属性表示请求的最大大小(以千字节为单位)。默认大小为 4096 KB (4 MB),允许的最大值是2097151。

示例代码:

<httpRuntime maxRequestLength="2097151"/>


使用以上配置进行测试,从WCF端获取1000万条长度为10的字符串是成功的。每个长度为10的字符串编码后约占32个字节,如此算来,成功传输的数据已经超过300M了,算得上不小的数字了,如果数据量比这还要大的话,怕是网速已经不能满足要求了,这时需要考虑其他的解决方案。