我不能发送超过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.。
此外,在<httpRuntime maxRequestLength="20480"/>文件中还有web.config设置。
发布于 2012-03-15 08:57:58
如果我正确地理解了您想要实现的目标--您希望创建接收大文件上传的WCF服务。
如果是这样的话,也许使用WCF流绑定可以帮助您实现目标。
不久前,我编写了一个服务,它使用类似于下面的配置来接受大文件上传:
<netTcpBinding>
<binding name="netTcpStreaming" sendTimeout="00:15:00" transferMode="Streamed" maxReceivedMessageSize="2147483648">
<security mode="None" />
</binding>
</netTcpBinding>https://stackoverflow.com/questions/9700640
复制相似问题