我目前有一个包含几个项目的解决方案,其中一个是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" bindingConfiguration="WSHttpBinding_IDBInteractionGateway"
contract="DBInteraction_Service.IDBInteractionGateway" name="WSHttpBinding_IDBInteractionGateway">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
对此(a static class):
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();
}
}
Run Code Online (Sandbox Code Playgroud)
出现该错误的原因是 WCF 客户端代理的默认构造函数从本地配置查找通道配置。您可以通过指定要使用/连接的绑定和地址来覆盖此行为。
这里有多个选项,每个选项都有不同的部署模型。
这些是我能立即想到的解决方案。让我们知道您决定做什么。
| 归档时间: |
|
| 查看次数: |
3919 次 |
| 最近记录: |