none
UPnP control point API unexpectedly subscribes to UPnP services, fails to find Xbox 360 & WMP 11 RRS feed

  • Question

  • I'm having issues using the UPnP APIs in the windows SDK, specifically I'm getting an unexpected exception when searching for media renderer services with my Xbox 360 or PC with WMP 11 on my network.  I'm using C# with a COM reference to the UPnP control point library, the simple code I'm trying:

     

    Code Snippet

    IUPnPDeviceFinder finder = new UPnPDeviceFinderClass();

    foreach (IUPnPDevice d in finder.FindByType("urn:schemas-upnp-org:device:MediaRenderer:1", 0))

    {

      Console.WriteLine("Device: {0}", d.FriendlyName);

      foreach (IUPnPService s in d.Services)

      {

        Console.WriteLine("\tService: {0}", s.ServiceTypeIdentifier);

      }

    }

     

     

    When my Xbox 360 or WMP 11 is on the network the program fails with an exception when foreach calls the d.Services enumerator:

     

    Device: Xbox 360

    Unhandled Exception: System.Runtime.InteropServices.COMException (0x80040501): Exception from HRESULT: 0x80040501
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.Runtime.InteropServices.CustomMarshalers.EnumeratorViewOfEnumVariant.MoveNext()
       at UPnPAVApp.Program.Main(String[] args) in C:\Users\Tony\Documents\Visual Studio 2008\Projects\UPnPAVApp\UPnPAVApp\Program.cs:line 19

     

    If the 360/WMP 11 are not on my network this code can find my Philips streamium (another UPnP media renderer) with no problem and enumerate the content directory, render control, and AV transport services. 

     

    The HRESULT above refers to a timeout error waiting for an event subscription.  I used wireshark to trace the communication with my 360 and can see when the IUPnPServices iterator is called my machine grabs the service description XML and then tries to subscribe to an event on the 360, here's a trace:

     

    SUBSCRIBE /Event/RenderingControl HTTP/1.1

    NT: upnp:event

    Callback: <http://192.168.1.103:2869/upnp/eventing/vspftrxvbe>

    Timeout: Second-1800

    User-Agent: Mozilla/4.0 (compatible; UPnP/1.0; Windows 9x)

    Host: 192.168.1.100:1026

    Content-Length: 0

    Connection: Close

    Cache-Control: no-cache

    Pragma: no-cache

     

    There's no response from the 360 or WMP 11 which matches the event subscription timeout error HRESULT exception.  Some questions:

     

    1. Why is the services iterator subscribing to an event?  Shouldn't this just be reading the service description XML?

     

    2. If it's not a bug that iterating over services will subscribe to events, why is this not documented?

     

    3. Finally, are the Microsoft UPnP APIs incompatible with the 360 and WMP 11?

    Sunday, August 10, 2008 7:45 AM

All replies

  • Hi, 

    I know that this is a very old question, but I'll answer just in case anyone else is looking for the answer like I did.

    You should try adding the below code before the foreach:

    IUPnPServiceEnumProperty upnpServiceEnumProperty = d.Services as IUPnPServiceEnumProperty;
    upnpServiceEnumProperty.SetServiceEnumProperty(0x1);

    After this the foreach should run properly. At least it did for me.

    More info about the SetServiceEnumProperty method:

    https://msdn.microsoft.com/en-us/library/windows/desktop/hh437166(v=vs.85).aspx

    The SetServiceEnumProperty method is used to indicate opt-in to the delayed Service Control Protocol Description (SCPD) download and event subscription for the IUPnPService objects enumerated from the IUPnPServices object.
    • Edited by Szabolcs Dézsi Saturday, August 12, 2017 3:37 AM Adding quote in case link goes down
    Saturday, August 12, 2017 3:26 AM