我有一堆遠程機器都通過HTTP運行相同的WCF服務。我有一箇中央配置實用程序,需要在運行時決定連接哪些設備。我不想在配置文件中定義所有端點,因爲這都是數據庫驅動的。在運行時指定WCF端點的IP地址
我天真地想這:
CustomerServiceClient GetClientForIPAddress(string ipAddress)
{
string address = String.Format("http://{0}/customerservice.svc", ipAddress);
var client = new CustomerServiceClient("?", address);
return client;
}
其中CustomerServiceClient是我的服務引用代理類,但(不出所料)它給了我下面的錯誤:
Could not find endpoint element with name '?' and contract 'SkyWalkerCustomerService.ICustomerService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
那麼,如何申報端點在運行時並將我的服務引用到它?
.NET 3.5
我相信這是一個複製http://stackoverflow.com/questions/1978962/how-to-change-endpoint-address-programatically-在-的客戶端站點 – 2010-03-23 08:40:03