2013-02-06 58 views
1

我正在嘗試註冊新的UPNP設備(並試圖瞭解它是如何工作的)。XML用於註冊新的UPNP設備

現在,我只是試圖創建一個簡單的測試,從那裏工作和構建的東西。

我使用UPnP設備主機現在,我已經下面的代碼:

IUPnPRegistrar registrar = (IUPnPRegistrar)new UPnPRegistrarClass(); 
String description = GetDescription(); 
String path = GetPath(); 
registrar.RegisterDevice(description, "Test1", "Init", "Container", path, 900); 

的GetDescription方法返回此:

<?xml version="1.0" encoding="utf-8" ?> 
<root xmlns="urn:schemas-upnp-org:device-1-0"> 
    <specVersion> 
     <major>1</major> 
     <minor>0</minor> 
    </specVersion> 
    <device> 
     <UDN>@@[email protected]@</UDN> 
     <friendlyName>Test device</friendlyName> 
     <deviceType>urn:schemas-upnp-org:device:XmsHostService:1</deviceType> 
     <manufacturer>Test</manufacturer> 
     <manufacturerURL>http://www.test.com</manufacturerURL> 
     <modelName>Test model name</modelName> 
     <modelNumber>0.1</modelNumber> 
     <modelDescription>Test device</modelDescription> 
     <modelURL>http://www.test.com/test-model-url</modelURL> 
     <serialNumber>0000001</serialNumber> 
     <UPC>00000-00001</UPC> 
     <serviceList> 
      <service> 
       <serviceType>urn:schemas-upnp-org:service:XmsHost:1</serviceType> 
       <serviceId>urn:upnp-org:serviceId:XmsHost</serviceId> 
       <controlURL></controlURL> 
       <eventSubURL></eventSubURL> 
       <SCPDURL>serviceDescription.xml</SCPDURL> 
      </service> 
     </serviceList> 
    </device> 
</root> 

而我的C:\ upnphost \服務.xml包含以下代碼:

<?xml version="1.0" encoding="utf-8"?> 
<scpd xmlns="urn:schemas-upnp-org:service-1-0"> 
    <specVersion> 
     <major>1</major> 
     <minor>0</minor> 
    </specVersion> 
    <actionList> 
     <action> 
      <name>GetPort</name> 
      <argumentList> 
       <argument> 
        <name>_ReturnValue</name> 
        <direction>out</direction> 
        <retval /> 
        <relatedStateVariable>A_ARG_TYPE_GetPort_RetType</relatedStateVariable> 
       </argument> 
      </argumentList> 
     </action> 
    </actionList> 
    <serviceStateTable> 
     <stateVariable sendEvents="no"> 
      <name>A_ARG_TYPE_GetPort_RetType</name> 
      <dataType>ui4</dataType> 
     </stateVariable> 
     <stateVariable sendEvents="no"> 
      <name>Port</name> 
      <dataType>ui4</dataType> 
     </stateVariable> 
    </serviceStateTable> 
</scpd> 

因此,首先,這個xml代碼看起來是否正確?

當我打電話寄存器設備,我得到這個異常:

System.ArgumentException was unhandled 
    Message=Value does not fall within the expected range. 
    Source=UPnPHostLib 
    StackTrace: 
     at UPnPHostLib.IUPnPRegistrar.RegisterDevice(String bstrXMLDesc, String bstrProgIDDeviceControlClass, String bstrInitString, String bstrContainerId, String bstrResourcePath, Int32 nLifeTime) 
     at UPnPHosterTester.Hoster.Start() in E:\Dev\Discovery\XMS_SW_Discovery_B\Solution\UPnPHosterTester\Hoster.cs:line 32 
     at UPnPHosterTester.Program.Main(String[] args) in E:\Dev\Discovery\XMS_SW_Discovery_B\Solution\UPnPHosterTester\Program.cs:line 19 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: 

但我看不出有什麼可以是錯誤的,900是接受的最小值。其他鏈接的問題:我知道,我必須實現IUPnPDeviceControl界面和我以前的代碼,而不是Test1的插入,但我不知道我應該在GetServiceObject返回

編輯 這裏是GetDescription方法:

private string GetDescription() 
{ 
    string xml = File.OpenText("DeviceDescription.xml").ReadToEnd(); 
    xml = xml.Replace("@@[email protected]@", "uuid:" +Guid.NewGuid().ToString()); 
    return xml; 
} 

編輯2 我嘗試,作爲推薦以除去所有非強制性屬性:

<?xml version="1.0" encoding="utf-8" ?> 
<root xmlns="urn:schemas-upnp-org:device-1-0"> 
    <specVersion> 
     <major>1</major> 
     <minor>0</minor> 
    </specVersion> 
    <device> 
     <UDN>@@[email protected]@</UDN> 
     <friendlyName>Test device</friendlyName> 
     <deviceType>urn:test-com:device:HostDevice:1</deviceType> 
     <manufacturer>Test</manufacturer> 
     <modelName>Test model name</modelName> 
    </device> 
</root> 

但我還是有相同的錯誤

編輯3 我沒發現有一個實用程序,檢查服務XML文件(而不是設備:()的良好的結構在這裏:http://msdn.microsoft.com/en-us/library/aa381938(v=vs.85).aspx您可以使用它與VS工作室命令提示符:validatesd.exe。它驗證了我的服務

+1

請停止編輯您的文章離開原標題。現在它甚至不提及XML。您不再有XML問題,但使用Win32 IUPnP特定功能參數。我的回答是回答最初的問題。 –

+0

@PavelZdenek我認爲它與XML內容有關,因爲我沒有看到我的c#調用可能超出範圍。在所有情況下,我很抱歉,我看到有點太遲了,我沒有發佈我遇到的最後一個錯誤。 – J4N

+0

好吧,我明白了。然後嘗試做我在答案中提出的建議。刪除所有不需要的東西,直到它工作,然後加回去。最重要的是,你不需要「服務」。 –

回答

1

COM對象progid必須對應於真實的東西,即:「Test1」必須是在當前註冊表中註冊的RegisterDevice調用成功的有效COM對象。

+0

事實上,它不是test1,而是我已經擁有的「Namespace.Class」。但就我所知,我應該註冊它,怎麼樣? – J4N

+0

這是另一個問題。你可以在.NET中創建一個COM對象。你可以谷歌這一點。例如:http://www45.brinkster.com/b3ck/code/dllcreation.html –

+0

好吧,我在想我必須在IUPnPRegistrar註冊這個類。但是如果我在同一個項目中,這仍然是強制性的嗎?它應該直接找到課程,不是? – J4N

1

您很快計算出XML頭。這已經寫:

如果您發佈的設備XML是真正完成,那麼你缺少XML 頭: 這是強制性不僅爲UPnP的範圍,但對於一般的XML。

如果您發佈的內容不完整,而且您有標題,我會先刪除所有可選元素。退出serviceList,presentationURL,UPC,serialNumber,可能更多。如果你不知道,mandatory spec is here。關於我的頭頂,我認爲UDN也有一個強制的格式(從uuid:開始),但是你已經在你的文章中留下了代碼,而不是結果字符串,所以我不知道你是否做得對。

+0

非常感謝您的回覆。我用GetDescription方法的內容更新了我的問題,它用uuid:替換了@@ UDN @@,所以我認爲這是好的。我試圖刪除您指示的所有屬性,但它不會更改異常。我還讀到,如果它是自定義類型,我們必須通過示例爲設備類型指定一個不同的「urn」,我這樣做了,但它仍然沒有改變任何東西。我將在一秒內發佈當前的XML我已經 – J4N