c#system.net.dns通用应用程序(W10)不工作 [英] c# system.net.dns universal app (W10) not working
问题描述
IPAddress [] ip = Dns.GetHostAddresses(www.google.com);
在univesal中获取IP地址c#windows应用程序 但是它显示错误
错误CS0103名称'Dns'不存在于当前上下文
我在控制台应用程序中尝试过,它的工作原理很好。命名空间System.Net不包含Dns在win 10通用应用程序。你可以告诉我,问题或其他解决方案在哪里?
我的CODE
使用System.Net;
public MainPage()
{
this.InitializeComponent();
}
private void button_Click(object sender,RoutedEventArgs e)
{
string zaznam = In.Text;
IPAddress [] ip = Dns.GetHostAddresses(www.google.com);
}
错误是正确的。 System.Net.Dns在。Windows运行时的网络框架。
可以使用Windows运行时类:调用Windows.Networking.Sockets。 DatagramSocket.GetEndpointPairsAsync 然后检查返回的 EndpointPairs
async任务ListEndpoints()
{
HostName host = new HostName(www.stackoverflow.com) ;
var eps = await DatagramSocket.GetEndpointPairsAsync(host,80);
foreach(eps中的EndpointPair ep)
{
Debug.WriteLine(EP {0} {1},新对象[] {ep.LocalHostName,ep.RemoteHostName});
}
}
I tried to get IP adress from DNS by using
IPAddress[] ip = Dns.GetHostAddresses("www.google.com");
in univesal c# windows app.
But it shows me error
Error CS0103 The name 'Dns' does not exist in the current context
I tried it in console app, it works perfectly. Namespace System.Net doesnt contain Dns in win 10 universal app. Could you tell me, where is problem or another solution?
My CODE
using System.Net;
public MainPage()
{
this.InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
string zaznam = In.Text;
IPAddress[] ip = Dns.GetHostAddresses("www.google.com");
}
The error is correct. System.Net.Dns is not available in the .Net Framework for Windows Runtime.
You can use the Windows Runtime classes instead: Call Windows.Networking.Sockets.DatagramSocket.GetEndpointPairsAsync then examine the returned EndpointPairs
async Task ListEndpoints()
{
HostName host = new HostName("www.stackoverflow.com");
var eps = await DatagramSocket.GetEndpointPairsAsync(host, "80");
foreach(EndpointPair ep in eps)
{
Debug.WriteLine("EP {0} {1}",new object[] { ep.LocalHostName, ep.RemoteHostName });
}
}
这篇关于c#system.net.dns通用应用程序(W10)不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!