3
我無法發送超過13 Mb的WCF服務。我得到超過最大請求長度例外我無法發送超過13 Mb的WCF服務(超過最大請求長度)
這裏是CreateServiceHost實施
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
IssuedSecurityTokenParameters itp = new IssuedSecurityTokenParameters(
"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1");
itp.IssuerAddress = new EndpointAddress(ConfigManager.ActAsSTS);
itp.IssuerMetadataAddress = new EndpointAddress(ConfigManager.ActAsSTS + "/mex");
// Create the security binding element
SecurityBindingElement sbe = SecurityBindingElement.CreateIssuedTokenForCertificateBindingElement(itp);
sbe.MessageSecurityVersion =
MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
// Create the HTTP transport binding element
HttpTransportBindingElement httpBe = new HttpTransportBindingElement();
httpBe.MaxReceivedMessageSize = httpBe.MaxBufferPoolSize = Constants.MaxFileSize;
TextMessageEncodingBindingElement encodingElement = new TextMessageEncodingBindingElement();
XmlDictionaryReaderQuotas quotas = encodingElement.ReaderQuotas;
quotas.MaxArrayLength = quotas.MaxBytesPerRead = quotas.MaxStringContentLength = quotas.MaxNameTableCharCount = quotas.MaxDepth = (int)Constants.MaxFileSize;
// Create the custom binding using the prepared binding elements
CustomBinding binding = new CustomBinding(sbe, encodingElement, httpBe);
EndpointAddress endpointAddress = new EndpointAddress(new Uri(ConfigManager.BaseAddress));
ServiceEndpoint endpoint = new ServiceEndpoint(contractDescription, binding, endpointAddress);
host.Description.Endpoints.Add(endpoint);
host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My,
X509FindType.FindByThumbprint, ConfigManager.ServiceCertificateThumbprint);
}
Constants.MaxFileSize = 20971520(20 MB = 20 * 1024 * 1024)
所有必要的設置MaxReceivedMessageSize ,MaxBytesPerRead ...已設置。
也有是在web.config文件<httpRuntime maxRequestLength="20480"/>
設置
這僅僅是一個在黑暗中拍攝,因爲我還沒有與WCF的工作很多,這是一個,而以前,但是由於您使用的是HTTP作爲傳輸方式,因此消息可能是base64編碼的,因此13 MB的實際數據被編碼爲20 MB的電纜? [文檔](http://msdn.microsoft.com/library/e1f13641.aspx)沒有提到任何類似的東西,我認爲base64通常會導致大小增加30%,所以也許不是這樣。 – BACON 2012-03-14 13:59:07