Yortw / RSSDP

Really Simple Service Discovery Protocol - a 100% .Net implementation of the SSDP protocol for publishing custom/basic devices, and discovering all device types on a network.

Home Page:http://yortw.github.io/RSSDP/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accessing Custom Headers from DiscoveredSsdpDevice

ciband opened this issue · comments

I am not sure how to access the custom response headers defined in SsdpRootDevice from the DeviceAvailable callback. It appears they are not packed in the ResponseHeaders and every time I call GetDeviceInfo(), I get an HTTP exception.

Any guidance you can give is appreciated. Thanks.

Hi,

Are you both publishing and searching for the device with RSSDP, or do you have a device on your network you know has custom headers and are just searching for it?

What is the name of the customer header?

What is the error you get from GetDeviceInfo(), and can you browse to the uri returned for the device using a web browser?

The unit tests for this are working so I put together a sample/test app, and it works too. If it's not working for you, can you please post some code or a link to a project the reproduces the issue? You can get my sample project here; https://1drv.ms/u/s!ArC3Ud4fUz-MgfmlXGO5ryd56TNnZ30

Assuming you have a header called "MyGuid" (just for example), you can retrieve the value like this;

  result.ResponseHeaders.GetValues("MyGuid").First()

This is the key code from the search end of my sample project;

				var locator = new Rssdp.SsdpDeviceLocator();
				var results = await locator.SearchAsync("urn:schemas-upnp-org:device:rssdptestdevice:1");
				foreach (var result in results)
				{
					Console.WriteLine(result.DescriptionLocation);
					if (result.ResponseHeaders.Contains("MyGuid"))
					{
						Console.WriteLine("Custom header found, first value is: " + result.ResponseHeaders.GetValues("MyGuid").First());
					}
				}

You can also enumerate all the headers if you don't know the specific name you want;

    foreach (var header in result.ResponseHeaders)
    {
         Console.WriteLine(header.Key + ": " + string.Join(", ", header.Value));
    }

My use case is publishing a custom device and then searching for that device. Given your sample, the behavior I am seeing is that if I put a header called "MyGuid" in the custom headers when I register my device on the server side, when I get the response from the search on the client side, that "MyGuid" header does not exist in the ResponseHeaders collection.

I have solved the problem another way so I am not really needing it work but I'm happy to help investigate as I can if needed.

Glad you have a work around, but if there's a problem with the library I'd really like to fix it. Unfortunately I can't reproduce your problem.

Could you please either try my sample and see if that works for you, or send me a project that reproduces the issue?

Thanks.

Test.zip

Attached is a sample program showing the error. Sorry for the delay in getting this to you.

It is a VS2017 solution with a console app.

Nevermind. I can't reproduce it now. I was probably using the library incorrectly.

No problem, thanks for your help in trying to resolve it.