枚举IPP打印机

时间:2015-05-11 17:17:11

标签: c# win-universal-app windows-10 mdns dns-sd

我正在研究Windows 10中基于DNS的服务发现,并从Build中找到this video。我对发现所做的唯一更改是将服务名称更改为" _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请求,因此我怀疑它是否存在通过应用功能获得网络权限的问题。

1 个答案:

答案 0 :(得分:0)

尝试使用watcher.Updated处理程序。即使它是空的,更新处理程序的存在也可能导致添加处理程序被触发。