如何为负载均衡器配置WCF服务

时间:2010-11-30 07:56:14

标签: wcf

如何为负载均衡器配置WCF服务并指定端点

1 个答案:

答案 0 :(得分:1)

您可以尝试编写一个custom service host factory,它将使用负载均衡器的网址作为基地址:

public class CustomServiceHostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(
        Type serviceType, Uri[] baseAddresses)
    {
        Uri uri = null;
        if (baseAddresses.Length < 2)
        {
            uri = baseAddresses[0];
        }
        else
        {
            // TODO: You need to choose the load balancer's url here:
            uri = baseAddresses[????];
        }
        return base.CreateServiceHost(serviceType, new Uri[] { uri });
    }
}