Jan
Jan

Reputation: 139

Referenced WCF Service doesn't use app.config

I coded a WCF service which is referenced in DLL. After I added that sevice reference an app.config was automatically generated with the requried data.

The client is using the dll to communicate with the wcf service...nothing special. But when I'm trying to create an object of the service reference..its crashing, saying that it wasn't able to find an endpoint adress.

I googled around and fixed it by passsing the the binding and adress to the service reference:

readonly BasicHttpBinding _binding = new BasicHttpBinding();
readonly EndpointAddress _address = new EndpointAddress("http://localhost:50309/CustomerService.svc");

using (CustomerServiceClient client = new CustomerServiceClient(_binding, _address))
{
    return client.GetActions(customerNumber);
}

I'm wondering now, why I have to pass those parameters, when those data is already in the automatically genrated app.config. I deleted the content of the app.config...and it seems those data isnt't used anywhere.

Am I doing something wrong?

EDIT:

app config in the dll project:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_ICustomerService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:50309/CustomerService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustomerService"
            contract="ServiceReference.ICustomerService" name="BasicHttpBinding_ICustomerService" />
    </client>
</system.serviceModel>
</configuration>    

Upvotes: 1

Views: 5454

Answers (2)

Piotr Justyna
Piotr Justyna

Reputation: 4996

Since your dll cannot run on its own, its needs an executable to be used from (whether it's a windows service, web service, a plain desktop application, etc.). Because of this, dlls use .config files of executables they are used from - this is why your dll seems to be ignoring its configuration.

Upvotes: 0

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56727

Please note the following: DLLs can not have their own app.config!

If you want the DLL to use configuration values, create them normally using the Properties for the DLL project, but then copy the settings section from the DLL's app.config to the EXE's app.config. Also, you need to copy the respective sectionGroup entry.

The DLL will then use the settings from the application's exe.config file.

Example of an app.config for an EXE project that provides settings for both the application and a DLL:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="ExeProject" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      <section name="DllProject" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>

  <applicationSettings>
    <ExeProject>
      <setting name="..." serializeAs="String">
        <value>...</value>
      </setting>
    </ExeProject>

    <DllProject>
      <setting name="..." serializeAs="String">
        <value>...</value>
      </setting>
    </DllProject>

  </applicationSettings>
</configuration>

Upvotes: 4

Related Questions