我可以';t向WCF服务发送超过13 Mb的请求(超过了最大请求长度)
本文关键字:请求 Mb 过了 WCF 服务 我可以 | 更新日期: 2023-09-27 18:27:40
我不能向WCF服务发送超过13 Mb的数据。我得到超过最大请求长度异常
这是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);
}
常数.MaxFileSize=20971520(20 Mb=20*1024*1024)
所有必要的设置MaxReceivedMessageSize,MaxBytesPerRead被设置。
web.config文件
<httpRuntime maxRequestLength="20480"/>
设置如果我正确理解您想要实现的目标——您想要创建接收大文件上传的WCF服务。
如果是这样的话,也许将WCF与流绑定一起使用将帮助您实现目标。
不久前,我写了一个服务,使用类似的配置接受大文件上传:
<netTcpBinding>
<binding name="netTcpStreaming" sendTimeout="00:15:00" transferMode="Streamed" maxReceivedMessageSize="2147483648">
<security mode="None" />
</binding>
</netTcpBinding>