我有一堆远程机器都通过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