Bonjour a tous !

Me voila bloqué depuis 2 jours sur mon code, je me décide donc a solliciter votre aide parce que j'ai vraiment explorer toute les pistes...

Mon programme : Service qui met en écoute des répertoires, dès lors qu'un PDF arrivent dans l'un de ces dossiers, celui -ci doit s'imprimer sur une imprimante (elle même associé a un dossier).

Je cherche donc a remplir le fichier App.config en y ajoutant des noeuds XML (ces noeuds représentant les répertoires que le programme va écouter).

Mon problème se situe lors de la récupération des informations de mon XML.

Mon XML :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
 
  <configSections>
    <section name="serverSection" type="WinServiceProject.serverSectionHandler, WinServiceProject"/>
    <section name="sitesSection" type="WinServiceProject.siteSectionHandler, WinServiceProject" />
  </configSections>
 
  <serverSection Type="WinServiceProject.serverSection, WinserviceProject">
    <NameServer>LCV3</NameServer>
    <AdresseServer>//lcv3.ciaf.local/</AdresseServer>
  </serverSection>
 
  <sitesSection type="WinServiceProject.siteSection, WinserviceProject">
    <site>
      <NameSite>Lezennes</NameSite>
      <PathSite>D:\PDF_ERP\Lezennes\</PathSite>
      <PrinterSite>AUTO_Lezennes_Photocopieur</PrinterSite>
   </site>
    <site>
      <NameSite>...</NameSite>
      <PathSite>...</PathSite>
      <PrinterSite>...</PrinterSite>
    </site>
  </sitesSection>
</configuration>
Références utilisés dans le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
    using System;
    using System.IO;
    using System.Diagnostics;
    using System.ComponentModel;
    using System.Configuration;
    using System.Xml;
    using System.Xml.Serialization;
Ma classe de typage :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    public class serverSection
    {
        private string _NameServer;
 
        public string NameServer
        {
            get { return _NameServer; }
            set { _NameServer = value; }
        }
 
        private string _AdresseServer;
 
        public string AdresseServer
        {
            get { return _AdresseServer; }
            set { _AdresseServer = value; }
        }
    }
Ma classe d'interface IConfigurationSectionHandler :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
    class serverSectionHandler : IConfigurationSectionHandler
    {
        public object Create(object parent, object configContext, XmlNode section)
        {
            XmlSerializer xs = new XmlSerializer(typeof(serverSection));
            XmlNodeReader xnr = new XmlNodeReader(section);
            return xs.Deserialize(xnr);
        }
    }
Enfin, ma méthode qui rempli une variable pour éxécution :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
            // Déclaration du serveur d'impression
            serverSection server = (serverSection)ConfigurationManager.GetSection("serverSection");
            string printerServer = server.AdresseServer;


NB: Lors de la compilation, aucune erreurs. Lors de l'installation du service non plus.
En revanche, dès qu'un PDF est matché dans le répertoire, le service s'arrête.
Pour information, je me suis appuyer sur ce tutorial Developpez.net