1

DLL で参照される WCF サービスをコーディングしました。そのサービス参照を追加した後、必要なデータで app.config が自動的に生成されました。

クライアントはdllを使用してwcfサービスと通信しています...特別なことは何もありません。しかし、サービス参照のオブジェクトを作成しようとすると、エンドポイント アドレスが見つからないと言ってクラッシュします。

私はグーグルで検索し、バインディングとアドレスをサービス参照に渡すことで修正しました:

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);
}

これらのデータが自動的に生成されたapp.configに既にあるのに、なぜこれらのパラメーターを渡す必要があるのか​​ 疑問に思っています。app.config の内容を削除しました...それらのデータはどこにも使用されていないようです。

私は何か間違ったことをしていますか?

編集:

dll プロジェクトのアプリ構成:

<?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>    
4

2 に答える 2

4

次の点に注意してください: DLL は独自app.config!

DLL で構成値を使用する場合は、通常、DLL プロジェクトのプロパティを使用して作成しますが、設定セクションを DLL からapp.configEXE の .xmlファイルにコピーしますapp.config。また、それぞれのsectionGroupエントリをコピーする必要があります。

DLL は、アプリケーションのexe.configファイルの設定を使用します。

app.configアプリケーションと DLL の両方の設定を提供する EXE プロジェクトの例:

<?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>
于 2013-03-28T09:32:34.797 に答える
0

dllは単独では実行できないため、使用する実行可能ファイルが必要です (Windows サービス、Web サービス、プレーンなデスクトップ アプリケーションなど)。このため、dll は使用元の実行可能ファイルの .config ファイルを使用します。これが、dll がその構成を無視しているように見える理由です。

于 2013-03-28T09:45:06.113 に答える