I am unable to send more than 13MB to WCF service (maximum request length exceeded)

I am unable to send more than 13 MB to the WCF service. I am getting exceeded maximum request length exception

Here is the implementation 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)

All the necessary settings MaxReceivedMessageSize, MaxBytesPerRead ... are set .

Also there is a parameter <httpRuntime maxRequestLength="20480"/>

in the web.config file

+3


source to share


1 answer


If I understand correctly what you want to achieve, you want to create a WCF service that receives large file uploads.

If so, perhaps using WCF with streaming bindings will help you achieve your goal.



A while ago I wrote a service that took large file uploads using a configuration like this:

<netTcpBinding>
 <binding name="netTcpStreaming" sendTimeout="00:15:00" transferMode="Streamed" maxReceivedMessageSize="2147483648">
          <security mode="None" />
  </binding>
</netTcpBinding>

      

0


source







All Articles