En utilisant web.config dans une application console c # WCF Hosted auto (réglage côté serveur MaxStringContentLength)

StackOverflow https://stackoverflow.com/questions/3856738

  •  27-09-2019
  •  | 
  •  

Question

Je simple 'autonome WCF fenêtres Console app, et je peux me relier très bien de mon client. J'ai un problème si l'envoi de grandes chaînes XML vers le serveur. Je reçois l'erreur suivante:

"System.Xml.XmlException: Le quota de longueur du contenu de chaîne maximale (8192) a été dépassée lors de la lecture des données XML Ce quota peut être augmentée en changeant la MaxStringContentLength propriété sur les XmlDictionaryReaderQuotas .... «

I peut définir le MaxStringContentLength dans le client en modifiant son fichier app.config (généré par svcutil.exe).

Mais sur le côté serveur que je n'ai nulle part je peux changer cela. Je l'ai lu sur un web.config fichier et je ne suis pas sûr si une application console WCF peut avoir un et si oui, comment je peux le lire et l'utiliser? Mon auto Code d'hébergement est ci-dessous:

static void RunWCFService()
{
    // Step 1 of the address configuration procedure: Create a URI to serve as the base address.
    Uri baseAddress = new Uri("http://localhost:8000/MyService/WcfService");

    // Step 2 of the hosting procedure: Create ServiceHost
    ServiceHost selfHost = new ServiceHost(typeof(MyServiceWcf), baseAddress);
    try
    {
        // Step 3 of the hosting procedure: Add a service endpoint.
        selfHost.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(), "MyService");

        // Step 4 of the hosting procedure: Enable metadata exchange.
        ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
        smb.HttpGetEnabled = true;
        selfHost.Description.Behaviors.Add(smb);                

        // Step 5 of the hosting procedure: Start (and then stop) the service.
        selfHost.Open();
        Console.WriteLine("Press <ENTER> to terminate service.");       
        Console.ReadLine();
        // Close the ServiceHostBase to shutdown the service.
        selfHost.Close();
    }
    catch (CommunicationException ce)
    {
        Console.WriteLine("An exception occurred: {0}", ce.Message);
        selfHost.Abort();
    }
 }
Était-ce utile?

La solution

Les données de configuration de WCF va dans le app.config de l'exe qui fait l'hébergement.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top