WCF services couldn't read configuration file

I have created some WCF services in class library. These services need some configuration values to work properly. So i added these configurations to the web.config file after deploying the services on IIS. The problem is that when i try to consume these services i get the following exception while reading the configurations:

System.ArgumentException: exePath must be specified when not running inside a stand alone exe.

Knowing that when i test the services it works fine before hosting them on IIS.

The question now what should i change to make the dll services able to be configured.

here is a portion of the web.config file.

    <children>
  <child name="service_config">
    <properties>
      <property name="connection_name" value="Photo" valueType="System.String" />
      <property name="data_access_interface" value="data_access" valueType="System.String" />
      <property name="is_client_db" value="false" valueType="System.String" />
      <property name="exchange_service" value="exchange_service_key" valueType="System.String" />
      <property name="max_file_size" value="1000" valueType="System.String" />
      <property name="email_sender" value="test@gmail.com" valueType="System.String" />
      <property name="email_body_template_name" value="test_files/Template.txt" valueType="System.String" />
      <property name="tablet_photo_size_height" value="100" valueType="System.String" />
      <property name="tablet_photo_size_width" value="90" valueType="System.String" />
      <property name="phone_photo_size_height" value="200" valueType="System.String" />
      <property name="phone_photo_size_width" value="180" valueType="System.String" />
      <property name="phone_photo_optimized_size_height" value="80" valueType="System.String" />
      <property name="phone_photo_optimized_size_width" value="60" valueType="System.String" />
      <property name="web_photo_size_height" value="127" valueType="System.String" />
      <property name="web_photo_size_width" value="170" valueType="System.String" />
      <property name="email_client_key" value="email_client_key" valueType="System.String" />
    </properties>

Answers


It's not entirely clear what you're trying to do, but it sounds like you're using ConfigurationManager.OpenExeConfiguration to read a specified section(s) of the config file. The error message you received gives you a good starting point for figuring out what the issue is - probably something to do with IIS not having a path to the exe.

You don't show the code you're using to get to the config file, and your posted configuration doesn't have a lot of context, so it's hard to tell you what to do.

However, I would use the <appSettings> section of the config file (available in both app.config and web.config files) to store these properties, and then you could retrieve them ConfigurationManager.AppSetting[keyName].

Something like this:

<appSettings>
  <add key="connection_name" value="Photo" />
  <add key="data_access_interface" value=data_access" />
  <!-- plus the rest of your values -->
</appSettings>

Then you'd simply use something like:

string connectionName = ConfigurationManager.AppSettings["connection_name"];
string dataAccesInterface = ConfigurationManager.AppSettings["data_access_interface"];

This would work whether you're running it as a stand alone exe or hosting it in IIS.

If there's a reason you don't want to (or can't) use the standard <appSettings> section, please update your question with the context around the <children> section plus how you're trying to access it so we can provide better guidance.


Need Your Help

Getting Full Output of System Log (Terminal)

java console terminal logging

I am making a console Java app where you can type in console commands like Terminal on Macintosh/Ubuntu/Windows Command Prompt and then it outputs it to a log.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.