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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 同一片海

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了,算得上不小的数字了,如果数据量比这还要大的话,怕是网速已经不能满足要求了,这时需要考虑其他的解决方案。