Tuesday, 15 September 2015

c# - XML To use to register a new UPNP device -



c# - XML To use to register a new UPNP device -

i'm trying register new upnp device(and trying understand how works way).

for now, i'm trying create simple test, have working , build there.

i'm using upnp device host now, i've next code:

iupnpregistrar registrar = (iupnpregistrar)new upnpregistrarclass(); string description = getdescription(); string path = getpath(); registrar.registerdevice(description, "test1", "init", "container", path, 900);

the getdescription method homecoming this:

<?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>@@udn@@</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>

and c:\upnphost\service.xml contains next code:

<?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>

so, first, xml code looks right?

when phone call register device, got exception:

system.argumentexception unhandled message=value not fall within expected range. source=upnphostlib stacktrace: @ upnphostlib.iupnpregistrar.registerdevice(string bstrxmldesc, string bstrprogiddevicecontrolclass, string bstrinitstring, string bstrcontainerid, string bstrresourcepath, int32 nlifetime) @ upnphostertester.hoster.start() in e:\dev\discovery\xms_sw_discovery_b\solution\upnphostertester\hoster.cs:line 32 @ upnphostertester.program.main(string[] args) in e:\dev\discovery\xms_sw_discovery_b\solution\upnphostertester\program.cs:line 19 @ system.appdomain._nexecuteassembly(runtimeassembly assembly, string[] args) @ system.appdomain.executeassembly(string assemblyfile, evidence assemblysecurity, string[] args) @ microsoft.visualstudio.hostingprocess.hostproc.runusersassembly() @ system.threading.threadhelper.threadstart_context(object state) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean ignoresyncctx) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state) @ system.threading.threadhelper.threadstart() innerexception:

but don't see can wrong, 900 min value accepted. other linked question: know have implement iupnpdevicecontrol interface , insert in previous code instead of test1, don't know should homecoming in getserviceobject

edit here getdescription method:

private string getdescription() { string xml = file.opentext("devicedescription.xml").readtoend(); xml = xml.replace("@@udn@@", "uuid:" +guid.newguid().tostring()); homecoming xml; }

edit 2 tried, recommended remove non-mandatory properties:

<?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>@@udn@@</udn> <friendlyname>test device</friendlyname> <devicetype>urn:test-com:device:hostdevice:1</devicetype> <manufacturer>test</manufacturer> <modelname>test model name</modelname> </device> </root>

but still have exact same error

edit 3 did found there utility check construction of service xml file(not device :() here: http://msdn.microsoft.com/en-us/library/aa381938(v=vs.85).aspx can utilize vs studio command prompt: validatesd.exe. validates service

the com object progid must correspond real, ie: "test1" must valid com object registered in current registry registerdevice phone call succeed.

c# .net xml upnp

No comments:

Post a Comment