locked
Could not iterate UPNP services of a device using microsoft UPNP.DLL RRS feed

  • Question

  • Hi Friends,

     

    I am facing a problem with Microsoft upnp.dll, i have 5.1.2600.2180 of upnp.dll.

    1) I wrote both VC++ as well as C# code; but could not iterate the device services.

    2) I also used get__item functions of IUPNPDevices and IUPNPServices but both  returned null reference.

     

    I am sending you C# code snippet.

    ==================================================================

    Code Snippet

    using UPNPLib;

    private void btnOK_Click(object sender, EventArgs e)

    {

    try

    {

    UPnPDeviceFinder pDeviceFinder = new UPnPDeviceFinder();

    // get device list for DEVICE URN

    UPnPDevices pDevices = pDeviceFinder.FindByType("urn:schemas-upnp-org:device:Printer:1", 0);

    foreach (UPnPDevice pDevice in pDevices)

    {

            if (pDevice != null)

              {

                  MessageBox.Show(pDevice.FriendlyName);

     

              // get device services

                  UPnPServices pServices = pDevice.Services;

                     

                     // While iterating the services it goes to catch block. Exception messge is  "Exception from HRESUT:0X80040500"

                       foreach (UPnPService pService in pServices)

                         {

                                 if (pService != null)

                                   MessageBox.Show(pService.Id.ToString());

                        }

                }

     }

    }

    catch (Exception ex)

    {

    MessageBox.Show(ex.Message);

    }

    }

     

     

     

    =====================================================================

    I tried the code both in VC++ and C#, it could not able to iterate services with both languaues.

     

    I also used get__item functions of IUPNPDevices and IUPNPServices but both  returned null reference.

     

    Please let me know the problem cause.

     

    Regards,

    Subhash Madhukar

     

     

    Monday, July 9, 2007 8:43 AM

Answers

  • First, it appears you are working with the desktop OS (Windows XP). this is a forum dedicated to mobile devices (Windows Mobile)

    Second, the error code you are seeing is UPNP_E_INVALID_DOCUMENT - it suggests, that your device has invalid device description document. The error is actually on the device side

    Monday, July 9, 2007 10:45 AM

All replies

  • First, it appears you are working with the desktop OS (Windows XP). this is a forum dedicated to mobile devices (Windows Mobile)

    Second, the error code you are seeing is UPNP_E_INVALID_DOCUMENT - it suggests, that your device has invalid device description document. The error is actually on the device side

    Monday, July 9, 2007 10:45 AM
  • The error also happens when you try the Microsoft uPnP samples in the Microsoft SDKs (since 2003, including 6 and 6.1).  So, if this was the XML document text that was at fault, then the Microsoft examples are incorrect too.

     

    The dimmer sample no longer works on either Windows XP SP3 nor Vista SP1 (32
    and 64-bit) when compiled with VC9 (VisualStudio 2008).

    The uPnP DLL does not register with RegDevice.exe (the source code has to be
    modified to use RegisterDevice instead of RegisterRunningDevice, and the
    GenericUCP.exe, although it finds the device, cannot enumerate any service
    (HRESULT error in iterator Next, same error as post above). GenericUCP.exe can enumerate services in
    actual hardware devices on the network (Internet gateway for example). I
    have tried both with the Microsoft examples and a uPnP device host written
    from scratch, and all exhibit the same behaviour.
    This uPnP section of the Windows SDK should probably be marked as not tested
    and abandonware.
     

    Monday, June 9, 2008 1:06 PM
  • I am also facing the same problem when itirating through the services, in my case i m writing a code to discover all the UPnP devices in the network, but only one device is listed.

    Please Help...

    Wednesday, August 19, 2009 10:51 AM
  • Well after spending days on this problem myself, I have figured it out.

    Microsofts UPNP implementation is BAD - VERY VERY BAD and should not be used.  It is not compliant to UPNP Specifications (even though they belong to the UPNP ORG and foster documents for the group)

    1. UPNP Spec specifies that a service description (SCPD) MUST have >= 0 Actions (meaning no actions is allowed)
    2. UPNP Spec specifies that a service description (SCPD) MUST have > 0 StateVariables (meaning at least 1)

    Microsft UPNP STACK REQUIRES BOTH AN ACTION and a STATEVARIABLE BE PRESENT, or it fails.

    Additionally, the "sendEvents" attribute in the StateVariable MUST BE = "yes"/"no".  Some vendors (Cisco) implement 0,1 or true/false on this field.  When Microsoft UPNP Stack encounters ANYTHING other than YES/NO, it fails.

    So, if you have a device which only sends a StateVariable and no Actions defined, MS UPNP will fail.

    If you have a vendor which sends something other than YES/NO in the sendEvents attribute, it will fail.

    Shawn

    • Proposed as answer by Garr Godfrey Thursday, January 10, 2019 9:44 PM
    • Unproposed as answer by Garr Godfrey Thursday, January 10, 2019 9:45 PM
    Tuesday, October 20, 2009 2:26 PM
  • It also chokes on the BOM character in an XML file.  I think that's appropriate according to UPnP spec, but it is easy to make that mistake when so many text editors invisibly add the UTF-8 signature.
    Thursday, January 10, 2019 9:46 PM