【发布时间】:2011-12-12 19:00:27
【问题描述】:
我有一个使用 netTCP 端点的 WCF 客户端项目。该项目编译为另一个项目引用的 DLL。我使用 AppSettings 在本地和远程 ip 端点之间切换,如下所示:
public EmbeddedClient()
{
//Grab ip to use: remote or local (used for simulator)
String location = ConfigurationSettings.AppSettings["ipAddress"];
String ip = ConfigurationSettings.AppSettings[location];
//Default to localhost if no appsetting was found
if (ip == null)
ip = "localhost";
String address = String.Format("net.tcp://{0}:9292/EmbeddedService", ip);
//Setup the channel to the service...
channelFactory = new ChannelFactory<IEmbeddedService>(binding, new EndpointAddress(address));
}
我的 App.Config 是我的 AppSettings 和 WCF 端点:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ipAddress" value="local"/>
<!-- Replace above value to "local" (Simulator) or "remote" (Harware)-->
<add key="local" value="localhost"/>
<add key="remote" value="192.168.100.42"/>
</appSettings>
<system.serviceModel>
<!--WCF Endpoints go here--->
</system.serviceModel>
</configuration>
当我编译项目时,appsetting 总是返回一个空值。我还注意到 app.config 在编译后被重命名为 Embedded_DCC_Client.dll.config 之类的东西。为什么找不到我的应用设置?为什么它返回null?谢谢。
【问题讨论】:
-
你能显示所涉及的(配置)文件吗?
标签: c# wcf app-config