我目前有一个包含几个项目的解决方案,其中一个是WCF服务.我创建了另一个使用静态类的投影,它基本上提供了一个WCF客户端实例的网关,如下所示:
public static class WSGateway
{
public static DBInteractionGatewayClient MR_WebService
{
get
{
return new DBInteractionGatewayClient();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是(或者我认为)我可以使用app.config仅在该库中的单个文件,然后其他项目可以只引用它并从该属性获取对该客户端的引用.
但问题是,当一个项目试图访问该属性时,会抛出一个异常,告诉我我需要app.config在应用程序中,当我将app.config我的网关库复制到应用程序时,它可以工作.
有没有办法避免app.config在应用程序中有多个文件,并且只有一个可能是一个库?
[更新]解决方案:
按照Anderson Imes的建议,现在我决定对类中的客户端引用配置进行硬编码,从而消除了对多个app.configs的需求.
因此,我从this(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" …Run Code Online (Sandbox Code Playgroud)