Best way to add xml configuration file to webservice

Discussion in 'ASP .Net' started by Allan Ebdrup, Apr 3, 2007.

  1. Allan Ebdrup

    Allan Ebdrup Guest

    I have a webservice in ASP.Net 2.0, I need to store and load a xml
    configuration file in relation to one of the web methods in my webservice.
    What's the best place to store and the best way to load my xml configuration
    file?
    I can't integrate the settings in web.config, it has to be a seperate file.

    Kind Regards,
    Allan Ebdrup
     
    Allan Ebdrup, Apr 3, 2007
    #1
    1. Advertising

  2. In the simplest terms,

    XmlDocument doc = new XmlDocument();
    doc.Load( Server.MapPath("yourdoc.xml") );

    Whatever your schema is for your configuration xml document, you take over
    from here.

    Peter

    --
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "Allan Ebdrup" wrote:

    > I have a webservice in ASP.Net 2.0, I need to store and load a xml
    > configuration file in relation to one of the web methods in my webservice.
    > What's the best place to store and the best way to load my xml configuration
    > file?
    > I can't integrate the settings in web.config, it has to be a seperate file.
    >
    > Kind Regards,
    > Allan Ebdrup
    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Apr 3, 2007
    #2
    1. Advertising

  3. Allan Ebdrup

    sloan Guest

    Peter,

    What about your cool AppSettings reader, that I added to?

    http://www.eggheadcafe.com/forums/ForumPost.asp?id=85647&ThreadID=85647&INTID=6

    It's 1.1, but I'm guessing a port over to 2.0 would't be that hard.



    Allan,
    Peter is correct about the "simplest of" using just a xml document.
    However, I'd check that out , and if you've never written a CustomHandler,
    I'd look into writing one.


    MyHandler : IConfigurationSectionHandler


    //' The section handler interprets and processes the settings
    defined in
    //' XML tags within a specific portion of a Web.config file and
    returns an
    //' appropriate configuration object .... based on the configuration
    settings.
    //' ( above exert from
    http://msdn.microsoft.com/library/d...uide/html/cpconcreatingnewsectionhandlers.asp )
    //' also see
    http://support.microsoft.com/default.aspx?scid=kb;en-us;309045 // Article
    ID : 309045


    The first one you do will take you some figuring out.

    The 2nd will be a little tougher. the 3rd..one and beyound.. will seem very
    trivial.


    At its core, the IConfigurationSectionHandler is a way to map xml values (on
    the .config file ) to some custom object holding those settings.

    I have a working example at:
    http://sholliday.spaces.live.com/blog/
    2/8/2006
    Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)










    "Peter Bromberg [C# MVP]" <> wrote in
    message news:...
    > In the simplest terms,
    >
    > XmlDocument doc = new XmlDocument();
    > doc.Load( Server.MapPath("yourdoc.xml") );
    >
    > Whatever your schema is for your configuration xml document, you take over
    > from here.
    >
    > Peter
    >
    > --
    > Site: http://www.eggheadcafe.com
    > UnBlog: http://petesbloggerama.blogspot.com
    > Short urls & more: http://ittyurl.net
    >
    >
    >
    >
    > "Allan Ebdrup" wrote:
    >
    > > I have a webservice in ASP.Net 2.0, I need to store and load a xml
    > > configuration file in relation to one of the web methods in my

    webservice.
    > > What's the best place to store and the best way to load my xml

    configuration
    > > file?
    > > I can't integrate the settings in web.config, it has to be a seperate

    file.
    > >
    > > Kind Regards,
    > > Allan Ebdrup
    > >
    > >
    > >
     
    sloan, Apr 3, 2007
    #3
  4. Thanks for the plug but he writes "I can't integrate the settings into
    web.config".
    :)
    Peter
    --
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "sloan" wrote:

    >
    > Peter,
    >
    > What about your cool AppSettings reader, that I added to?
    >
    > http://www.eggheadcafe.com/forums/ForumPost.asp?id=85647&ThreadID=85647&INTID=6
    >
    > It's 1.1, but I'm guessing a port over to 2.0 would't be that hard.
    >
    >
    >
    > Allan,
    > Peter is correct about the "simplest of" using just a xml document.
    > However, I'd check that out , and if you've never written a CustomHandler,
    > I'd look into writing one.
    >
    >
    > MyHandler : IConfigurationSectionHandler
    >
    >
    > //' The section handler interprets and processes the settings
    > defined in
    > //' XML tags within a specific portion of a Web.config file and
    > returns an
    > //' appropriate configuration object .... based on the configuration
    > settings.
    > //' ( above exert from
    > http://msdn.microsoft.com/library/d...uide/html/cpconcreatingnewsectionhandlers.asp )
    > //' also see
    > http://support.microsoft.com/default.aspx?scid=kb;en-us;309045 // Article
    > ID : 309045
    >
    >
    > The first one you do will take you some figuring out.
    >
    > The 2nd will be a little tougher. the 3rd..one and beyound.. will seem very
    > trivial.
    >
    >
    > At its core, the IConfigurationSectionHandler is a way to map xml values (on
    > the .config file ) to some custom object holding those settings.
    >
    > I have a working example at:
    > http://sholliday.spaces.live.com/blog/
    > 2/8/2006
    > Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > "Peter Bromberg [C# MVP]" <> wrote in
    > message news:...
    > > In the simplest terms,
    > >
    > > XmlDocument doc = new XmlDocument();
    > > doc.Load( Server.MapPath("yourdoc.xml") );
    > >
    > > Whatever your schema is for your configuration xml document, you take over
    > > from here.
    > >
    > > Peter
    > >
    > > --
    > > Site: http://www.eggheadcafe.com
    > > UnBlog: http://petesbloggerama.blogspot.com
    > > Short urls & more: http://ittyurl.net
    > >
    > >
    > >
    > >
    > > "Allan Ebdrup" wrote:
    > >
    > > > I have a webservice in ASP.Net 2.0, I need to store and load a xml
    > > > configuration file in relation to one of the web methods in my

    > webservice.
    > > > What's the best place to store and the best way to load my xml

    > configuration
    > > > file?
    > > > I can't integrate the settings in web.config, it has to be a seperate

    > file.
    > > >
    > > > Kind Regards,
    > > > Allan Ebdrup
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Apr 3, 2007
    #4
  5. Sorry, Sloan. I should have read your post first. Yes your enhancement might
    be appropriate!
    Peter

    --
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "sloan" wrote:

    >
    > Peter,
    >
    > What about your cool AppSettings reader, that I added to?
    >
    > http://www.eggheadcafe.com/forums/ForumPost.asp?id=85647&ThreadID=85647&INTID=6
    >
    > It's 1.1, but I'm guessing a port over to 2.0 would't be that hard.
    >
    >
    >
    > Allan,
    > Peter is correct about the "simplest of" using just a xml document.
    > However, I'd check that out , and if you've never written a CustomHandler,
    > I'd look into writing one.
    >
    >
    > MyHandler : IConfigurationSectionHandler
    >
    >
    > //' The section handler interprets and processes the settings
    > defined in
    > //' XML tags within a specific portion of a Web.config file and
    > returns an
    > //' appropriate configuration object .... based on the configuration
    > settings.
    > //' ( above exert from
    > http://msdn.microsoft.com/library/d...uide/html/cpconcreatingnewsectionhandlers.asp )
    > //' also see
    > http://support.microsoft.com/default.aspx?scid=kb;en-us;309045 // Article
    > ID : 309045
    >
    >
    > The first one you do will take you some figuring out.
    >
    > The 2nd will be a little tougher. the 3rd..one and beyound.. will seem very
    > trivial.
    >
    >
    > At its core, the IConfigurationSectionHandler is a way to map xml values (on
    > the .config file ) to some custom object holding those settings.
    >
    > I have a working example at:
    > http://sholliday.spaces.live.com/blog/
    > 2/8/2006
    > Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > "Peter Bromberg [C# MVP]" <> wrote in
    > message news:...
    > > In the simplest terms,
    > >
    > > XmlDocument doc = new XmlDocument();
    > > doc.Load( Server.MapPath("yourdoc.xml") );
    > >
    > > Whatever your schema is for your configuration xml document, you take over
    > > from here.
    > >
    > > Peter
    > >
    > > --
    > > Site: http://www.eggheadcafe.com
    > > UnBlog: http://petesbloggerama.blogspot.com
    > > Short urls & more: http://ittyurl.net
    > >
    > >
    > >
    > >
    > > "Allan Ebdrup" wrote:
    > >
    > > > I have a webservice in ASP.Net 2.0, I need to store and load a xml
    > > > configuration file in relation to one of the web methods in my

    > webservice.
    > > > What's the best place to store and the best way to load my xml

    > configuration
    > > > file?
    > > > I can't integrate the settings in web.config, it has to be a seperate

    > file.
    > > >
    > > > Kind Regards,
    > > > Allan Ebdrup
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Apr 3, 2007
    #5
  6. Hi Allan,

    As other members have suggested,you can use the XmlDocument class to load
    the XML configurure file. Or if you want a strong-type accessing to the
    content of the XML document, you can consider using XML Serialization to
    map your XML document to .NET custom classes:

    #Introducing XML Serialization
    http://msdn2.microsoft.com/en-us/library/182eeyhh(vs.71).aspx

    Also, if the content of the XML configuration file will be used within the
    entire lifecycle of your ASP.NET webservice, you can also cache it in
    ASP.NET runtime Cache collection so as to avoid frequent file I/O
    operations. Another benifit of using Cache is that ASP.NET cache has a
    "FileDependency" which can help you cache objects depend on a disk file.
    Whenever the specified file has been changed, the cached object will be
    invalidate and removed from cache. This can help you update the cached
    configuration with better performance:

    #Cache Management in ASP.NET
    http://www.codeproject.com/aspnet/cachemanagementinaspnet.asp

    Hope this also helps.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================



    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Apr 4, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stan
    Replies:
    3
    Views:
    480
    Brock Allen
    May 5, 2005
  2. Karthikesh Raju

    best way to read a configuration file

    Karthikesh Raju, Mar 3, 2004, in forum: Python
    Replies:
    5
    Views:
    442
    Kevin Dahlhausen
    Mar 3, 2004
  3. kaush
    Replies:
    1
    Views:
    190
    Peter Kelcey
    Oct 17, 2005
  4. Vili
    Replies:
    1
    Views:
    202
  5. Eddy Xu
    Replies:
    5
    Views:
    125
    Eddy Xu
    Apr 11, 2008
Loading...

Share This Page