Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5975873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:08:52+00:00 2026-05-22T21:08:52+00:00

I am currently registering a WCF service using the following code: var factory =

  • 0

I am currently registering a WCF service using the following code:

var factory = new DefaultServiceHostFactory();
RouteTable.Routes.Add(new ServiceRoute("XXXEndPoint", factory, IXXXEndPoint)));

This is all well and good however I also need to change the MaxStringContentLength property of the reader quota settings. It appears that the default value of 8192 is used, regardless of my attempts to change this and I guess this is from the DefaultServiceModel?

Are there any suitable hooks to override this setting on the DefaultServiceModel, or should I be deriving my own service host/model classes, or am I going about this the wrong way?

Any suggestions appreciated.

EDIT: Please note that the configuration of the binding must be performed programatically (not via configuration files).

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:08:53+00:00Added an answer on May 22, 2026 at 9:08 pm

    You can make it by extending host factory.
    By little modification of code bellow you can pass an additional parameter to WCFServiceHostFactory to set it from Global.asax
    I have used the classes bellow to always set it to Int32.MaxValue

    //in Global.asax

    routes.Add(new ServiceRoute(routePrefix,
                new WCFServiceHostFactory(),
                serviceType));
    

    //WCFServiceHostFactory.cs

    namespace MyServices.MyService
    {
        public class WCFServiceHostFactory:WebServiceHostFactory
        {
            protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            {
                WCFServiceHost host = new WCFServiceHost(serviceType, baseAddresses);
    
                return host;
            }
        }
    }
    

    //WCFServiceHost.cs

    namespace MyServices.MyService
    {
        public class WCFServiceHost:WebServiceHost
        {
            public WCFServiceHost(): base ()
            {
            }
    
            public WCFServiceHost (object singletonInstance, params Uri [] baseAddresses)
              : base (singletonInstance, baseAddresses)
            {
            }
    
            public WCFServiceHost(Type serviceType, params Uri[] baseAddresses)
              : base (serviceType, baseAddresses)
            {
            }
    
    
    
            protected override void OnOpening ()
            {
              base.OnOpening ();
    
              foreach (Uri baseAddress in BaseAddresses) {
                bool found = false;
                foreach (ServiceEndpoint se in Description.Endpoints)
                    if (se.Address.Uri == baseAddress)
                    {
                        found = true;
                        ((WebHttpBinding)se.Binding).ReaderQuotas.MaxStringContentLength = Int32.MaxValue;//here you set it and also set it below
                    }
                if (!found) {
                  if (ImplementedContracts.Count > 1)
                    throw new InvalidOperationException ("Service '"+ Description.ServiceType.Name + "' implements multiple ServiceContract types, and no endpoints are defined in the configuration file. WebServiceHost can set up default endpoints, but only if the service implements only a single ServiceContract. Either change the service to only implement a single ServiceContract, or else define endpoints for the service explicitly in the configuration file. When more than one contract is implemented, must add base address endpoint manually");
                  var  enumerator = ImplementedContracts.Values.GetEnumerator ();
                  enumerator.MoveNext ();
                  Type contractType = enumerator.Current.ContractType;
                  WebHttpBinding binding = new WebHttpBinding();
                  binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue; //here also
              AddServiceEndpoint (contractType, binding, baseAddress);
                }
    
              }
    
              foreach (ServiceEndpoint se in Description.Endpoints)
                if (se.Behaviors.Find<WebHttpBehavior> () == null)
                  se.Behaviors.Add (new WebHttpBehavior ());
    
              // disable help page.
              ServiceDebugBehavior serviceDebugBehavior = Description.Behaviors.Find<ServiceDebugBehavior> ();
              if (serviceDebugBehavior != null) {
                serviceDebugBehavior.HttpHelpPageEnabled = false;
                serviceDebugBehavior.HttpsHelpPageEnabled = false;
              }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm registering every user control separately in Web.config <pages validateRequest=false> <controls> <add tagPrefix=cc1
I have implemented Unity within my Asp.Net MVC2 project. I am currently registering my
When registering .NET assemblies for COM Interop, I do two things, currently in this
I am currently in the process of converting old Web 1.0 code to meet
This is what I am currently using for registration: def register(request): if request.method ==
I am trying to detect when particular applications are launched. Currently I am using
I have been tasked with developing a Firefox add-on that is capable of registering
We're currently writing some software that we want to protect. We thought that registering
Currently I have use the following approach to setup change notification on any of
I have a working application using Json.NET (newtonsoft) as a custom serializer. Currently I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.