首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我不能发送超过13 Mb到WCF服务(超过最大请求长度)

我不能发送超过13 Mb到WCF服务(超过最大请求长度)
EN

Stack Overflow用户
提问于 2012-03-14 11:01:04
回答 1查看 1.6K关注 0票数 3

我不能发送超过13 Mb到WCF服务。我得到最大请求长度超过了异常

下面是CreateServiceHost实现

代码语言:javascript
复制
    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设置。

EN

回答 1

Stack Overflow用户

发布于 2012-03-15 08:57:58

如果我正确地理解了您想要实现的目标--您希望创建接收大文件上传的WCF服务。

如果是这样的话,也许使用WCF流绑定可以帮助您实现目标。

不久前,我编写了一个服务,它使用类似于下面的配置来接受大文件上传:

代码语言:javascript
复制
<netTcpBinding>
 <binding name="netTcpStreaming" sendTimeout="00:15:00" transferMode="Streamed" maxReceivedMessageSize="2147483648">
          <security mode="None" />
  </binding>
</netTcpBinding>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9700640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档