我正在研究 Windows 10 中基于 DNS 的服务发现,并从 Build 中找到了这个视频。我对发现所做的唯一更改是将服务名称更改为“_ipp._tcp”。但是,即使我知道网络上有超过 15 台启用 IPP 的打印机(我可以使用 ipptool、IOS 和 Android 代码成功识别这些打印机),我也没有得到任何点击。
我已经检查并仔细检查了拼写错误。我在 appxmanifest 文件中包含了所有网络功能。
这是我的代码,非常简单:
public sealed partial class MainPage : Page
{
static Guid DnsSdProtocol = new Guid("{4526e8c1-8aac-4153-9b16-55e86ada0e54}");
string queryString = "System.Devices.AepService.ProtocolId:={" + DnsSdProtocol + "} AND " +
"System.Devices.Dnssd.Domain:=\"local\" AND System.Devices.Dnssd.ServiceName:=\"_ipp._tcp\"";
DeviceWatcher watcher;
public MainPage()
{
this.InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
watcher = DeviceInformation.CreateWatcher(queryString,
new String[]
{
"System.Devices.Dnssd.HostName",
"System.Devices.Dnssd.ServiceName",
"System.Devices.Dnssd.TextAttributes",
"System.Devices.IpAddress" },
DeviceInformationKind.AssociationEndpointService
);
watcher.Added += Watcher_Added;
watcher.Start();
}
private void Watcher_Added(DeviceWatcher sender, DeviceInformation args)
{
System.Diagnostics.Debug.WriteLine("found device");
}
}
有没有其他人有这方面的经验并且可以帮助找出为什么没有找到设备?我的查询正确吗?设置 DeviceWatcher 时我还需要做其他事情吗?
更新
我已经验证了请求正在创建,因为它们出现在 Wireshark 中。它们看起来与正在创建的其他 mdns 请求相同。我还验证了我可以创建返回发现设备的 SSDP 请求,所以我怀疑这是通过应用程序功能的网络权限问题。