App.config in Server Object Extension?

3136
10
08-29-2012 02:04 PM
AnandTrivedi1
New Contributor II
Hi,
I am trying to use App.config file in Server object extension that I am building. The app.config file does gets copied to the SOE (verified by renaming the .soe file to .zip file and checking the contents). But I am unable to read that app.config file.

I was wondering if you guys have come across similar issues.

Thanks!
Tags (2)
0 Kudos
10 Replies
RichardWatson
Frequent Contributor
app.config usually applies to the application, i.e. ArcMap, ArcGISSOC, etc.
0 Kudos
KevinGooss
Occasional Contributor
what do you mean by 'unable to read'?
Are you using System.Configuration?
do you have appSetting keys in the config file?
what happens when you try to read those keys?
what is the error?
0 Kudos
AnandTrivedi1
New Contributor II
what do you mean by 'unable to read'?
Are you using System.Configuration?
do you have appSetting keys in the config file?
what happens when you try to read those keys?
what is the error?


Yes I am using System.configuration and other general ways you would try to read app.config. I am trying to read the app.config in my construct folder of the server object extension. However, it is not finding the app.config file and the keys and the values are appearing as null.
0 Kudos
AnandTrivedi1
New Contributor II
app.config usually applies to the application, i.e. ArcMap, ArcGISSOC, etc.


So, for SOE, how would you go about it if you want the flexibility of specifying parameters outside the dll or .soe file. I can use property but the requirement is to use config files.
0 Kudos
RichardWatson
Frequent Contributor
At least in versions prior to 10.1, I think that you could find ArcGISSOC.exe and place ArcGISSOC.config in that directory.  Essentially you need to find the host executable image and place the config file next to it.  I've done this very thing in order to configure log4net when used in conjunction with ArcMap.exe.

I personally do not think that doing this is a good idea.  Perhaps you could create your own XML configuration file and literally read it yourself.  Just look in whatever directory your assembly is executing out of.
0 Kudos
AnandTrivedi1
New Contributor II
At least in versions prior to 10.1, I think that you could find ArcGISSOC.exe and place ArcGISSOC.config in that directory.  Essentially you need to find the host executable image and place the config file next to it.  I've done this very thing in order to configure log4net when used in conjunction with ArcMap.exe.

I personally do not think that doing this is a good idea.  Perhaps you could create your own XML configuration file and literally read it yourself.  Just look in whatever directory your assembly is executing out of.


Thank you for the reply. I agree going with the first option is not a good idea.

I have even tried creating my own xml and reading it with no success. The xml does gets packaged in the soe (you can see it after changing .soe extension to .zip). However, it appears while executing it still doesn't read it. I am not aware of how the soe is exploded and where it is placed in ArcGIS Server - may be the dll gets seperated and gets loaded somewhere and that's why it is not able to find the app.config file (which is technically <dllName>.dll.config file.
0 Kudos
UdayBurrey
New Contributor

Anand, 

Have you got it working finally? I also have similar issue. Is there a way we can use the configuration file to read the parameters instead of setting properties in Contruct? 

TIA

0 Kudos
nicogis
MVP Frequent Contributor

Yes, you can write similar code

var appConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
string myValue= appConfig.AppSettings.Settings["myKeyName"].Value;

your app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="myKeyName" value="testValue"/>
  </appSettings>
</configuration>
0 Kudos
UdayBurrey
New Contributor

Thanks for your response Domenico. 

Every change in the app.config has to be compiled and the modified .soe file has to be registered once again with ArcGIS server. I am trying to avoid registering the SOE again and again for every configuration change.

0 Kudos