我有一個項目是使用netTCP端點的WCF客戶端。該項目編譯成另一個項目引用的DLL。我使用的AppSettings像這樣的本地和遠程IP端點之間進行切換:App.config AppSettings返回null
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總是返回null。我還注意到,編譯後,app.config被重命名爲Embedded_DCC_Client.dll.config。爲什麼它無法找到我的appsettings?爲什麼它返回null?謝謝。
,你能否告訴有關(配置)文件的文件夾? –