title: Why my UPnP device doesn't return services registered in UPnP SCPD xml file?
body: <p>I register a UPnP device with:</p>
  
  <pre><code>var o: IUPnPRegistrar;
      W: string;
      R: HRESULT;
  begin
    w := TFile.ReadAllText('UPnPDevice_Desc.xml');
    o := CoUPnPRegistrar.Create as IUPnPRegistrar;
    R := o.RegisterDevice(w, ...);
  end;
  </code></pre>
  
  <p>File UPnPDevice_Desc.xml:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;root xmlns="urn:schemas-upnp-org:device-1-0"&gt;
  &lt;specVersion&gt;
      &lt;major&gt;1&lt;/major&gt;
      &lt;minor&gt;0&lt;/minor&gt;
  &lt;/specVersion&gt;
  
  &lt;device&gt;
      &lt;pnpx:X_deviceCategory xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11"&gt;Other&lt;/pnpx:X_deviceCategory&gt;
  &lt;!--&lt;pnpx:X_hardwareId xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11"&gt;Microsoft/SampleDevice/10000/urn:microsoft-com:device:SampleDimmerDevice:1&lt;/pnpx:X_hardwareId&gt;--&gt;
  &lt;!--    &lt;df:X_containerId xmlns:df="http://schemas.microsoft.com/windows/2008/09/devicefoundation"&gt;{8C7B310D-90F8-40D4-B5EA-71D81821DEA6}&lt;/df:X_containerId&gt;--&gt;
      &lt;deviceType&gt;urn:example-com:device:uPnPDevice:1&lt;/deviceType&gt;
      &lt;friendlyName&gt;My UPNP Device Hosted by Windows&lt;/friendlyName&gt;
      &lt;manufacturer&gt;Example Company&lt;/manufacturer&gt;
      &lt;manufacturerURL&gt;http://www.example.com/&lt;/manufacturerURL&gt;
      &lt;modelDescription&gt;My UPnP Device&lt;/modelDescription&gt;
      &lt;modelName&gt;uPnPDevice&lt;/modelName&gt;
      &lt;modelNumber&gt;1001&lt;/modelNumber&gt;
      &lt;modelURL&gt;http://www.example.com/&lt;/modelURL&gt;
      &lt;serialNumber&gt;123456&lt;/serialNumber&gt;
      &lt;UDN&gt;uuid:RootDevice&lt;/UDN&gt;
      &lt;UPC&gt;00000-00001&lt;/UPC&gt;
  
      &lt;serviceList&gt;
        &lt;service&gt;
          &lt;serviceType&gt;urn:schemas-upnp-org:service:SwitchPower:1&lt;/serviceType&gt;
          &lt;serviceId&gt;urn:upnp-org:serviceId:SwitchPower:1&lt;/serviceId&gt;
          &lt;controlURL&gt;&lt;/controlURL&gt;
          &lt;eventSubURL&gt;&lt;/eventSubURL&gt;
          &lt;SCPDURL&gt;UPnPDevice_SCPD.xml&lt;/SCPDURL&gt;
        &lt;/service&gt;
      &lt;/serviceList&gt;
  
      &lt;presentationURL&gt;DimmerPresentation.htm&lt;/presentationURL&gt;
  &lt;/device&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>File UPnPDevice_SCPD.xml:</p>
  
  <pre><code>&lt;scpd xmlns="urn:schemas-upnp-org:service-1-0"&gt;
  &lt;specVersion&gt;
      &lt;major&gt;1&lt;/major&gt;
      &lt;minor&gt;0&lt;/minor&gt;
  &lt;/specVersion&gt;
  &lt;actionList&gt;
      &lt;action&gt;
          &lt;name&gt;MagicOn&lt;/name&gt;
      &lt;/action&gt;
  &lt;/actionList&gt;
  &lt;serviceStateTable&gt;
      &lt;stateVariable&gt;
          &lt;name&gt;OSMajorVersion&lt;/name&gt;
          &lt;dataType&gt;i4&lt;/dataType&gt;
      &lt;/stateVariable&gt;
      &lt;stateVariable&gt;
          &lt;name&gt;OSMinorVersion&lt;/name&gt;
          &lt;dataType&gt;i4&lt;/dataType&gt;
      &lt;/stateVariable&gt;
      &lt;stateVariable&gt;
          &lt;name&gt;OSBuildNumber&lt;/name&gt;
          &lt;dataType&gt;i4&lt;/dataType&gt;
      &lt;/stateVariable&gt;
      &lt;stateVariable&gt;
          &lt;name&gt;OSMachineName&lt;/name&gt;
          &lt;dataType&gt;string&lt;/dataType&gt;
      &lt;/stateVariable&gt;
  &lt;/serviceStateTable&gt;
  &lt;/scpd&gt;
  </code></pre>
  
  <p>I can confirm the UPnP device has been hosted in UPnP device host service by using IUPnPDeviceFinder or M-SEARCH to find the device.</p>
  
  <p>The registry</p>
  
  <pre><code>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\UPnP Device Host\Description
  </code></pre>
  
  <p>also contain the corresponding information:</p>
  
  <pre><code>[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\UPnP Device Host\Description\{00BB4949-F3B2-4F5A-B534-C6FE61B71F4E}]
  
  [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\UPnP Device Host\Description\{00BB4949-F3B2-4F5A-B534-C6FE61B71F4E}\Files]
  
  [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\UPnP Device Host\Description\{00BB4949-F3B2-4F5A-B534-C6FE61B71F4E}\Files\{B11E040A-6858-48BA-B1BD-85B4E8FCBA73}]
  "Filename"="M:\\uPNP\\D16\\Win32\\Debug\\UPnPDevice_SCPD.xml"
  "Mimetype"="text/xml; charset=\"utf-8\""
  
  [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\UPnP Device Host\Description\{00BB4949-F3B2-4F5A-B534-C6FE61B71F4E}\UDN Mappings]
  
  [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\UPnP Device Host\Description\{00BB4949-F3B2-4F5A-B534-C6FE61B71F4E}\UDN Mappings\uuid:RootDevice]
  @="uuid:00bb4949-f3b2-4f5a-b534-c6fe61b71f4e"
  </code></pre>
  
  <p>When query for services of the UPnP device using</p>
  
  <pre><code>var Enum: IEnumVARIANT;
      Fetched: Cardinal;
      K: OleVariant;
      P: IUPnPService;
      W: WideString;
      D: IUPnPDevice
  begin
    ...
    if D.Services.Count &gt; 0 then begin
      Enum := D.Services._NewEnum as IEnumVARIANT;
      Enum.Reset;
      while Enum.Next(1, K, Fetched) = S_OK do begin
        P := IDispatch(K) as IUPnPService;
      end;
    end;
  end;
  </code></pre>
  
  <p>The D.Services.Count is 1 but the Enum doesn't fetch any services.  Variable Fetched always return 0.</p>
  
  <p>If I have query for Media Player UPnP device, It did return the services available.</p>
  
  <p>Any ideas what's wrong with my UPnP Device that doesn't return services as indicated in SCPD xml file?</p>
  
  <p>Once I registered the device, the XML description will change to:</p>
  
  <pre><code>&lt;root xmlns="urn:schemas-upnp-org:device-1-0"&gt;
      &lt;specVersion&gt;
          &lt;major&gt;1&lt;/major&gt;
          &lt;minor&gt;0&lt;/minor&gt;
      &lt;/specVersion&gt;
  
      &lt;device&gt;
          &lt;pnpx:X_deviceCategory xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11"&gt;Other&lt;/pnpx:X_deviceCategory&gt;
  &lt;!--
  &lt;pnpx:X_hardwareId xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11"&gt;Microsoft/SampleDevice/10000/urn:microsoft-com:device:SampleDimmerDevice:1&lt;/pnpx:X_hardwareId&gt;
  --&gt;
  &lt;!--
  &lt;df:X_containerId xmlns:df="http://schemas.microsoft.com/windows/2008/09/devicefoundation"&gt;{8C7B310D-90F8-40D4-B5EA-71D81821DEA6}&lt;/df:X_containerId&gt;
  --&gt;
          &lt;deviceType&gt;urn:example-com:device:uPnPDevice:1&lt;/deviceType&gt;
              &lt;friendlyName&gt;My UPNP Device Hosted by Windows&lt;/friendlyName&gt;
              &lt;manufacturer&gt;Example Company&lt;/manufacturer&gt;
              &lt;manufacturerURL&gt;http://www.example.com/&lt;/manufacturerURL&gt;
              &lt;modelDescription&gt;My UPnP Device&lt;/modelDescription&gt;
              &lt;modelName&gt;uPnPDevice&lt;/modelName&gt;
              &lt;modelNumber&gt;1001&lt;/modelNumber&gt;
              &lt;modelURL&gt;http://www.example.com/&lt;/modelURL&gt;
              &lt;serialNumber&gt;123456&lt;/serialNumber&gt;
              &lt;UDN&gt;uuid:9742f52d-f39f-4eaf-9ecf-bb742e9d79e9&lt;/UDN&gt;
              &lt;UPC&gt;00000-00001&lt;/UPC&gt;
              &lt;serviceList&gt;
                  &lt;service&gt;
                      &lt;serviceType&gt;urn:schemas-upnp-org:service:SwitchPower:1&lt;/serviceType&gt;
                      &lt;serviceId&gt;urn:upnp-org:serviceId:SwitchPower:1&lt;/serviceId&gt;
                      &lt;controlURL&gt;
                          /upnphost/udhisapi.dll?control=uuid:9742f52d-f39f-4eaf-9ecf-bb742e9d79e9+urn:upnp-org:serviceId:SwitchPower:1
                      &lt;/controlURL&gt;
                      &lt;eventSubURL&gt;
                          /upnphost/udhisapi.dll?event=uuid:9742f52d-f39f-4eaf-9ecf-bb742e9d79e9+urn:upnp-org:serviceId:SwitchPower:1
                      &lt;/eventSubURL&gt;
                      &lt;SCPDURL&gt;
                          /upnphost/udhisapi.dll?content=uuid:40c39217-e93b-4d0a-b5e0-abc582b2a2ed
                      &lt;/SCPDURL&gt;
                  &lt;/service&gt;
              &lt;/serviceList&gt;
          &lt;presentationURL&gt;
              /uuid:9742f52d-f39f-4eaf-9ecf-bb742e9d79e9/DimmerPresentation.htm?/upnphost/udhisapi.dll?content=uuid:9742f52d-f39f-4eaf-9ecf-bb742e9d79e9+uuid:9742f52d-f39f-4eaf-9ecf-bb742e9d79e9
          &lt;/presentationURL&gt;
      &lt;/device&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Note the controlURL, eventSubURL and SCPDURL has been changed.  Accessing</p>
  
  <pre><code>http://localhost:2869/upnphost/udhisapi.dll?content=uuid:40c39217-e93b-4d0a-b5e0-abc582b2a2ed
  </code></pre>
  
  <p>return exact content as file UPnPDevice_SCPD.xml.</p>