【发布时间】:2017-12-25 12:05:04
【问题描述】:
根据下图,IIS 上可能有多个 WebSite 和多个服务,
所以我唯一将它们分开的东西是 Hostname ,在其他站点中,兄弟服务可能会一起调用,所以我决定更改 hostname 如果它们不在本地主机上,所以在服务中我尝试了类似的东西这个:
HostName = OperationContext.Current.Channel.LocalAddress.Uri.Host.ToString();
当我通过它的代理调用另一个服务时,我在服务中我 Rehome
public void ReHome(string hostName)
{
if (!string.IsNullOrEmpty(hostName))
{
if (this.Endpoint.Address.Uri.DnsSafeHost.ToLower().Equals("localhost"))
{
string newAddress = string.Format("{0}://{1}{2}/{3}", Endpoint.Address.Uri.Scheme
, hostName, string.IsNullOrEmpty(Endpoint.Address.Uri.Port.ToString()) ? string.Empty : ":" + Endpoint.Address.Uri.Port.ToString()
, Endpoint.Address.Uri.AbsolutePath);
this.Endpoint.Address = new EndpointAddress(newAddress);
}
}
}
在服务中调用示例:
using (var hisProxy = new HISIntegrationClient("hisIntegrationEndPoint", Internals.SYSTEM))
{
hisProxy.ReHome(HostName);
....
}
OperationContext.Current.Channel.LocalAddress.Uri.Host 也给我上面图片中提到的我想要的东西吗?
【问题讨论】: