WCF配置文件相關操作技巧解析
如何運用WCF實現上傳數據大小的控制,取決于我們對WCF配置文件的修改方法。在這里就為大家詳細介紹一下WCF配置文件的一些修改技巧,以達到文件大小控制的目的。#t#
默認情況下,wcf的服務端如果發生異常是不會將詳細異常發送給客戶端的,客戶端只能提到以下籠絡的提示異常信息:
由于內部錯誤,服務器無法處理該請求。有關該錯誤的詳細信息,請打開服務器上的 IncludeExceptionDetailInFaults (從 ServiceBehaviorAttribute 或從 配置行為)以便將異常信息發送回客戶端,或在打開每個 Microsoft .NET Framework 3.0 SDK 文檔的跟蹤的同時檢查服務器跟蹤日志。
于是做了一下修改:
- [ServiceBehavior(AddressFilterMode
AddressFilterMode = AddressFilterMode.
Any, IncludeExceptionDetailInFaults = true)] - public class CommunicationWithUnit :
IContractForUnit - {...}
其中第一個是去防火墻的,第二個是客戶端顯示錯誤詳細信息的。
主要還是數據大小問題,于是又去解決:
在WCF配置文件進行修改.
舊的WCF配置文件:
- < binding name="BasicHttpBinding_
ICentaMiddleService" closeTimeout="00:01:00"- openTimeout="00:01:00" receiveTimeout=
"00:10:00" sendTimeout="00:01:00"- allowCookies="false" bypassProxyOnLocal=
"false" hostNameComparisonMode="StrongWildcard"- maxBufferSize="65536" maxBuffer
PoolSize="524288" maxReceivedMessageSize="65536"- messageEncoding="Text" textEncoding=
"utf-8" transferMode="Buffered"- useDefaultWebProxy="true">
- < readerQuotas maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"- maxBytesPerRead="4096" maxName
TableCharCount="16384" />- < security mode="None">
- < transport clientCredentialType=
"None" proxyCredentialType="None"- realm="" />
- < message clientCredentialType=
"UserName" algorithmSuite="Default" />- < /security>
- < /binding>
新的WCF配置文件:
- < binding name="BasicHttpBinding_
ICentaMiddleService" closeTimeout="00:01:00"- openTimeout="00:01:00" receiveTimeout=
"00:10:00" sendTimeout="00:01:00"- allowCookies="false" bypassProxyOnLocal=
"false" hostNameComparisonMode="StrongWildcard"- maxBufferSize="65536" maxBufferPoolSize=
"524288" maxReceivedMessageSize="9223372036854775807"- messageEncoding="Text" textEncoding=
"utf-8" transferMode="Streamed"- useDefaultWebProxy="true">
- < readerQuotas maxDepth="6553500"
maxStringContentLength="2147483647"- maxArrayLength="6553500" maxBytesPerRead=
"6553500" maxNameTableCharCount="6553500" />- < security mode="None">
- < transport clientCredentialType="None"
proxyCredentialType="None"- realm="" />
- < message clientCredentialType="UserName"
algorithmSuite="Default" />- < /security>
- < /binding>
以上就是針對文件上傳大小控制對WCF配置文件進行的修改方法。