1 回答

TA貢獻1790條經驗 獲得超9個贊
我認為你的想法是最好的解決方案,通過使用 DNS.GetHostAddress 來獲取服務器的實際 IP 地址。它只能由域名系統來完成。DiscoveryClient 僅返回服務器端定義的服務端點地址,該地址僅適用于控制臺應用程序托管的服務。
<service name="ConsoleApp3.TestService">
<!--the below service endpoint address is returned as defined here-->
<endpoint address="http://10.157.13.69:6666" binding="wsHttpBinding" contract="ConsoleApp3.ITestService" ></endpoint>
<!--this line code will return domain-->
<!--<endpoint address="http://vabqia969vm:6666" binding="wsHttpBinding" contract="ConsoleApp3.ITestService"></endpoint>-->
<!--for exposing the service-->
<endpoint kind="discoveryEndpoint" address="http://10.157.13.69:6666/exterior" binding="wsHttpBinding" ></endpoint>
</service>
對于 IIS 中托管的服務,無論站點綁定的類型如何,都僅返回域名。這種情況下,我們就只能利用DNS了。
foreach (EndpointDiscoveryMetadata item in response.Endpoints)
{
//retrieve IP address
System.Net.IPHostEntry hostinfo = System.Net.Dns.GetHostEntry(item.Address.Uri.Host);
string IPAddress = hostinfo.AddressList[2].ToString();
Console.WriteLine(IPAddress);
}
如果有什么需要我幫忙的,請隨時告訴我。
- 1 回答
- 0 關注
- 125 瀏覽
添加回答
舉報