C# Windows Service XML

Posted by Goober on Stack Overflow See other posts from Stack Overflow or by Goober
Published on 2010-04-16T06:53:23Z Indexed on 2010/04/16 7:03 UTC
Read the original article Hit count: 364

Filed under:
|
|
|
|

Scenario

I have a windows service written in C# that performs some processing based on parsing an XML file and use that data to carry out various tasks. The service also does various bits of logging - which uses settings from an APP.Config file.

The Problem

When the service is compiled, installed and run, the XML file seems to disappear. I'm getting the impression that it is just ignored or something like that.

So far

I've tried using TWO App.Config files, one named App.Config that contains settings for the service, and the other called MyService.exe.config that contains all of the data that was used in the XML file (the idea being that I can parse the XML from a config file that actually gets compiled and appears in my installation directory.

However

When I do this, all that happens is that ONE config file appears (with the name MyService.exe.config), but it contains the contents of the App.Config file and not the XML data that I want to parse.

What I need

All I want is to have a config file for my settings, and an XML file for my data.

Question

Is this possible? I know the application works as it was originally built as a console application that ran fine.

Other

The application has to be designed this way (as in, I need my data stored as XML, and my settings stored in a config file).

Thoughts

If I could somehow combine the contents of the two files into ONE config file, that would be one way of solving the problem. However, I have tried this and of course I get a "Type Initialisation Exception", as the config file cannot interprate the XML data (probably because the tags are custom and do not form any part of the config schema - or something like that).

Ideas

Please could someone explain to me if it is possible for me to have an XML file AND a config file that will actually be compiled and stored in my installation directory for the service when it is run?

CODE

Custom XML/Data Config File

   <?xml version="1.0" encoding="utf-8" ?> 
  <configuration> 
  <servers> 
<SV066930> 
  <add name="Name" value = "SV066930" /> 
  <processes> 
<SimonTest1> 
  <add name="ProcessName" value="notepad.exe" /> 
  <add name="CommandLine" value="C:\\WINDOWS\\system32\\notepad.exe    C:\\WINDOWS\\Profiles\\TA2TOF1\\Desktop\\SimonTest1.txt" /> 
          </SimonTest1> 
 </processes> 
  </SV066930> 
  </servers> 
 </configuration> 

APP.Config Settings File

   <?xml version="1.0" encoding="utf-8" ?> 
  <configuration> 
   <configSections> 
     <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxx" /> 
   </configSections> 
  <connectionStrings> 
 <add name="DB" connectionString="Data Source=etc......" /> 
  </connectionStrings> 
  </configuration> 

Help greatly appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about Windows