In our example, we will only implement one service: the DigitalSecurityCameraStillImage:1
interface provided by the UPnP forum (http://upnp.org/specs/ha/UPnP-ha-StillImage-v1-Service.pdf). The service description XML already exists; it is published by the UPnP Forum. However, we still need to create a file in our project that our device can use to publish the SCPD XML document. The file we will create will be called StillImageService.xml
, and we will put it in the UPnP folder together with the other UPnP-related files. We will also make sure the file is created as an embedded resource of the project.
The service file begins with a specification of the UPnP version that is used:
<?xml version="1.0" encoding="utf-8"?> <scpd xmlns="urn:schemas-upnp-org:service-1-0"> <specVersion> <major>1</major> <minor>0</minor> </specVersion>
Directly following the version follows a list of actions published by the service. Each action is defined by a name and a list of arguments. Each argument in turn also has a name, a direction, and a reference to a state variable that defines the underlying state variable and the data type being referenced. The first action in our example is defined as follows:
<actionList> <action> <name>GetAvailableEncodings</name> <argumentList> <argument> <name>RetAvailableEncodings</name> <direction>out</direction> <relatedStateVariable>AvailableEncodings </relatedStateVariable> </argument> </argumentList> </action> </actionList>
After having listed all the actions, the corresponding state variables need to be listed. In our example, there will be variables that send events and variables that do not. State variables are defined as follows. Only the first two state variables are listed here:
<serviceStateTable> <stateVariable sendEvents="no"> <name>AvailableEncodings</name> <dataType>string</dataType> </stateVariable> <stateVariable sendEvents="yes"> <name>DefaultEncoding</name> <dataType>string</dataType> </stateVariable> </serviceStateTable>
When we are done with listing our state variables, we are done with the service document:
</scpd>
For a list of data types available in UPnP, refer to Appendix J, Data types in UPnP.
We need each device to have a unique identity or UDN. To do this, we add a udn
property to our DefaultSettings
class. We initialize the property with a new GUID
so that the first time the application is run and a new object created, it will receive a new unique GUID
identifier as udn
.
private string udn = Guid.NewGuid().ToString();
The public interface for our property is defined as follows:
[DBShortStringClipped (false)] public string UDN { get { return this.udn; } set { if(this.udn != value) { this.udn = value; this.Modified = true; } } }