locked
Help please with custom section in app.config for WCF service library RRS feed

  • Question

  • User446859115 posted

    I've been trying (without success) to create and utilize a custom section in the app.config file for my WCF service.

    After combing through the documentation it looks to me that this example comes closest to my needs; whowever it's geared towards using the web.config file. Another issue I have modifying this example to my needs is that when I try to build the project it complains with the error:

    "XML_Feed_svc.XML_File_list_ConfigurationHandler" does not implement interface member 'System.Configurration.IConfigurationSectionHandler.Create(object, object, System.Xml.XmlNode)' "

    The example for the IConfigurationSectionHandler interface states the that approach has been depreciated. So now what am I to do.

    Another feature I need to have in accessing this custom section is the ability to reference a list (or array if you prefer) of elements in my custom section. How to do this is not at all clear from the example.

    So here's what I've got to date. Feel free to direct me in the appropriate direction to get this working.

    In my app.config I have:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <sectionGroup name="XML_File_List_group">
          <section name="XML_File_List" type="WCF_XML_Feed.XML_File_List" allowLocation="true" allowDefinition="Everywhere" />
        </sectionGroup>
      </configSections>
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
        <add key="ClientSettingsProvider.ServiceUri" value="" />
      </appSettings>
      <XML_File_List_Group>
        <XML_File_List>
          <file Filename="VPS_ops_config" Full_Pathname="C:\syncs\ftpmonitor\ftpServers2watch.xml" ReadingEnabledRoles="*" WritingEnabledRoles="VP Admin" />
          <file Filename="convertParams" Full_pathname="C:\syncs\ftpmonitor\convert_params.xml" ReadingEnabledRoles="*" WritingEnabledRoles="VP Admin" />
        </XML_File_List>
      </XML_File_List_Group>
      <system.web>

    In the WCF service file (called service1.cs) I have:

     public class XML_File_List_Section
        {
            public IEnumerable<FileItemInfo> FileItemInfo { get; set; }
        }
    
        public class FileItemInfo
        {
            public string Filename { get; set; }
            public string Pathname { get; set; }
            public string[] ReadEnabledRoles { get; set; }
            public string[] WriteEnabledRoles { get; set; }
        }
    
        public class XML_File_List : ConfigurationSection
        {
            [ConfigurationProperty("XML_File_List", DefaultValue = null, IsRequired = false)]
            public XmlNode XML_File_List_node
            {
                get
                {
                    XmlNode tp = (XmlNode)this["XML_File_List"];
                    return (XmlNode) this["XML_File_List"] ;
                }
                set
                {
    
                }
            }
    
            [ConfigurationProperty("XML_File_List2", DefaultValue = null, IsRequired = false)]
            public FileItemInfo[] ListOfFiles
            {
                get
                {
                    int x = 1; // break point holder
                    return null;
                }
                set
                {
    
                }
            }
        }
    

    Any help would be appriciated.


     


     

     

    Tuesday, May 7, 2013 1:16 PM

All replies

  • User446859115 posted

    Does anyone have any ideas on this. I'm still trying to get this working.

     

    Thursday, May 16, 2013 12:25 PM
  • User-488622176 posted

    You're using old style code. Please check this article : http://msdn.microsoft.com/en-us/library/ms228056%28v=vs.100%29.aspx

    It explains (with sample) how to do this in .NET 4.x

    Thursday, May 16, 2013 4:36 PM
  • User446859115 posted

    I have looked at this section however, if you read the "note" in the article this approach has been depreciated and recommends only using this approach for .net 1.1 or earlier. The note refers you back to the appraoch I was trying to follow. Unless I miss read something.

     

    Thursday, May 16, 2013 5:59 PM