By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Best way to add xml configuration file to webservice

P: n/a
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
Apr 3 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
Apr 3 '07 #2

P: n/a

Peter,

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

http://www.eggheadcafe.com/forums/Fo...=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/de...onhandlers.asp )
//' also see
http://support.microsoft.com/default...b;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]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:FC**********************************@microsof t.com...
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


Apr 3 '07 #3

P: n/a
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/Fo...=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/de...onhandlers.asp )
//' also see
http://support.microsoft.com/default...b;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]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:FC**********************************@microsof t.com...
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
>
>
>


Apr 3 '07 #4

P: n/a
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/Fo...=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/de...onhandlers.asp )
//' also see
http://support.microsoft.com/default...b;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]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:FC**********************************@microsof t.com...
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
>
>
>


Apr 3 '07 #5

P: n/a
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/lib...hh(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/ca...ntinaspnet.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/subscripti...ult.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/subscripti...t/default.aspx.

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

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 4 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.