WCF使用外部config筆記

摘要:WCF使用外部config筆記

  1. 改用System.ServiceModel.Configuration.ConfigurationChannelFactory<T>來產生Proxy
  2. 建立時傳入Configuration物件
  3. 可以利用Enterprise Library的ConfigurationSourceFactory來算簡化找尋外部config
var source = ConfigurationSourceFactory.Create();

var config = source.GetSection("system.serviceModel");

ConfigurationChannelFactory<IXXXXChannel> stockChannelFactory =
	new ConfigurationChannelFactory<IXXXXChannel>(
		regionId, config.CurrentConfiguration, null);
var client = stockChannelFactory.CreateChannel();
client.DoSomething();