WindowsDevicePortalWrapper
WindowsDevicePortalWrapper copied to clipboard
There's no way to find Device Portal instances via DNS-SD
Device Portal advertises over DNS-SD so that other clients can find it. The Wrapper project should have a generic way of detecting and connecting to the service, regardless of what DeviceFamily it belongs to.
Docs for the DNS-SD broadcast are on MSDN
For what it's worth, here's a snippet for finding device portals and generating the url:
private void FindDevices()
{
// Doc: https://docs.microsoft.com/en-us/windows/uwp/debug-test-perf/device-portal#service-features-and-notes
var aqsFilter = "System.Devices.AepService.ProtocolId:={4526e8c1-8aac-4153-9b16-55e86ada0e54} AND System.Devices.Dnssd.Domain:=\"local\" AND System.Devices.Dnssd.ServiceName:=\"_wdp._tcp\"";
var properties = new[] {
"System.Devices.Dnssd.HostName",
"System.Devices.Dnssd.ServiceName",
"System.Devices.Dnssd.PortNumber",
"System.Devices.Dnssd.TextAttributes",
"System.Devices.IpAddress",
};
var watcher = DeviceInformation.CreateWatcher(aqsFilter, properties, DeviceInformationKind.AssociationEndpointService);
watcher.Added += (sender, args) =>
{
Debug.WriteLine("Added: " + args.Name);
var ipAddresses = args.Properties["System.Devices.IpAddress"] as string[];
var remotePort = args.Properties["System.Devices.Dnssd.PortNumber"].ToString();
var textAttributes = args.Properties["System.Devices.Dnssd.TextAttributes"] as string[];
Debug.WriteLine($"\t{ipAddresses.FirstOrDefault()}:{remotePort} : {string.Join(",", textAttributes)}");
string securePort = textAttributes.Where(t => t.StartsWith("S=")).Select(t => t.Substring(2)).FirstOrDefault() ?? "0";
string scheme = "http";
if (securePort != "0")
{
scheme = "https";
remotePort = securePort;
}
string devicePortalUrl = $"{scheme}://{ipAddresses.FirstOrDefault()}:{remotePort}";"?";
};
watcher.Updated += (sender, args) => Debug.WriteLine("Updated: " + args.Id);
watcher.EnumerationCompleted += (sender, args) => Debug.WriteLine("EnumerationCompleted");
watcher.Start();
}
Hi all
I'm looking for a solution to discover the devices in a WPF application, the shared code above is for an UWP.
Anyone any idea how I can use DNS-SD to discover the Win10 IoT devices in my network ?
On a Desktop app, you can get the above code working by installing the Nuget package Microsoft.Windows.SDK.Contracts
https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance
Note that your project's Nuget package format MUST be set to PackageReference
.
You can right click the packages.json
and convert it (Migrate packages.config to PackageReference)
https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference