Best way to add xml configuration file to webservice

A

Allan Ebdrup

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
 
G

Guest

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
 
S

sloan

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)
 
S

Steven Cheng[MSFT]

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top