私は現在、いくつかのプロジェクトで解決策を持っており、そのうちの1つはWCFサービスです。C#WCF:サービスへのアクセスを提供する共有ライブラリに1つのapp.configを持っています
public static class WSGateway
{
public static DBInteractionGatewayClient MR_WebService
{
get
{
return new DBInteractionGatewayClient();
}
}
}
私はその意志単一app.config
ファイルを使用することができること(またはそう思った)ので、これは:私は基本的に、このようなのようなWCFクライアントのインスタンスへのゲートウェイを提供する静的クラスで投影別の作成しましたそのライブラリ内にいるだけで、他のプロジェクトはそれを参照し、そのプロパティからそのクライアントへの参照を取得できます。
しかし、問題は、プロジェクトがそのプロパティにアクセスしようとしたとき、例外は私がアプリケーションにapp.config
に必要な、と私は、アプリケーションに私のゲートウェイライブラリapp.config
をコピーするとき、それが動作することを私に言って投げているということです。
アプリケーションで複数app.config
のファイルを持つと、おそらく単一のライブラリにちょうど1つを有する回避する方法はありますか?
[更新]ソリューション:Anderson Imes "の提案に続き
は、今の私は、クラス内のクライアントの参照設定をハードコーディングすることを決定したため、複数のapp.config
のための必要性を排除しました。これに
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDBInteractionGateway" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="6000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<security mode="None"/>
<readerQuotas maxDepth="6000000" maxStringContentLength="6000000" maxArrayLength="6000000"
maxBytesPerRead="6000000" maxNameTableCharCount="6000000" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://agnt666laptop:28666/DBInteractionGateway.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDBInteractionGateway"
contract="DBInteraction_Service.IDBInteractionGateway" name="WSHttpBinding_IDBInteractionGateway">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
(static class
):
したがって、私はこのことから私の設定(app.config
)を翻訳し
public static class WSGateway
{
private static WSHttpBinding binding;
private static EndpointAddress endpointAddress;
static WSGateway()
{
var readerQuotas = new XmlDictionaryReaderQuotas()
{
MaxDepth = 6000000,
MaxStringContentLength = 6000000,
MaxArrayLength = 6000000,
MaxBytesPerRead = 6000000,
MaxNameTableCharCount = 6000000
};
binding = new WSHttpBinding(SecurityMode.None) {MaxReceivedMessageSize = 6000000, ReaderQuotas = readerQuotas};
endpointAddress = new EndpointAddress("http://agnt666laptop:28666/DBInteractionGateway.svc");
}
public static DBInteractionGatewayClient MR_WebService
{
get
{
return new DBInteractionGatewayClient(binding, endpointAddress);
}
}
public static void ExecuteCommand(Action<DBInteractionGatewayClient> command)
{
var ws = MR_WebService;
command.Invoke(ws);
ws.Close();
}
}
解決策を投稿していただきありがとうございます...この決定を下すことを試みている他の人に役立つでしょう。 –
ヒントをありがとう。あなたの例は切り捨てられているので、私は以下の私のソリューションを貼り付けました(http://stackoverflow.com/questions/746107/c-wcf-having-a-single-app-config-in-a-shared-library-that-provides- access-to-th/7652518#7652518) –
コードが切り詰められている理由がわかりません。とにかく、ここにそれはどのように見えるべきですか:http://pastebin.com/8jii24JV –