[英]How to get the correct local address URI when hosting IIS site on multiple bindings?
I have configured a simple service in IIS with multiple port bindings. 我已经在IIS中使用多个端口绑定配置了一个简单的服务。 The current channel local address is always the same no matter which port was called.
无论调用哪个端口,当前通道的本地地址始终是相同的。
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class TestService : ITestService
{
public string Test()
{
return OperationContext.Current.Channel.LocalAddress.Uri.Port.ToString();
}
}
Call to testHost2:7772
-> returns 7772 调用
testHost2:7772
>返回7772
Call to testHost1:7771
-> returns 7772 too 调用
testHost1:7771
>也返回7772
You could use this below code to get the hostname and the port using WCF: 您可以使用以下代码使用WCF获取主机名和端口:
var test = OperationContext.Current.Host.BaseAddresses[0].Authority;
or 要么
Uri uri = OperationContext.Current.IncomingMessageHeaders.To ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.