WCF终结点地址和监听地址没这么简单
终结点地址一般指逻辑地址:采用baseAddress+address格式指定;
而监听地址一般由listenUri和listenUriMode共同决定
如果listenUriMode.Explicit则严格按照listenUri设置,首先检验listenUri是否存在,如果不存在则使用address地址,如果存在则首先检验listenUri格式是否正确,listenUri采用baseAddress+listenUri,如果不存在则使用baseAddress+address,其中对address也要先进行检验,如果满足格式要求,直接使用address地址..
程序实例:
Uri[] baseAddress=new Uri[2];baseAddress[0]=new Uri("http://127.0.0.1:3721/calculatorService1");baseAddress[0]=new Uri("net.tcp://127.0.0.1:3721/calculatorService3");using(ServiceHost host=new ServiceHost(typeof(CalculatorService),baseAddress)){ host.Opened+=delegate { Console.WriteLine("服务已经启动!"); } host.Open(); int i=0; foreach(ChannelDiapatcher channelDiapatcher in host.ChannelDispatchers) { Console.WriteLine("{0}:{1}",++i,channelDispatcher.Listener.Uri);} Console.read();
}终结点配置:<endpoint binding="basicHttpBinding" Contract="ICalculator" listenUri="http://www.hawaisir.com" listenUriMode="Explicit"/><endpoint address="net.tcp://www.haweisir.com" binding="netTcpBinding" Contract="ICalculator" listenUri="baiducom" listenUriMode="Unique"/>结果:http://www.hawaisir.com/net.tcp://127.0.0.1:5428/calculatorService3/baiducom <endpoint binding="basicHttpBinding" Contract="ICalculator" listenUri="http://www.hawaisir.com" listenUriMode="Explicit"/><endpoint address="net.tcp://www.haweisir.com" binding="netTcpBinding" Contract="ICalculator" listenUriMode="Unique"/>http://www.hawaisir.com/net.tcp://www.haweisir.com:52112/ <endpoint binding="basicHttpBinding" Contract="ICalculator" listenUri="http://www.hawaisir.com" listenUriMode="Explicit"/><endpoint address="baiducom" binding="netTcpBinding" Contract="ICalculator" listenUriMode="Unique"/>http://www.hawaisir.com/net.tcp://127.0.0.1:5468/calculatorService3/baiducom <endpoint binding="basicHttpBinding" Contract="ICalculator" listenUri="http://www.hawaisir.com" listenUriMode="Explicit"/><endpoint binding="netTcpBinding" Contract="ICalculator" listenUri="net.tcp://www.haweisir.com" listenUriMode="Unique"/>http://www.hawaisir.com/net.tcp://www.haweisir.com:65150/