I am rather new to WCF (or rest, or Json for that matter) and I'd like to have some expert opinions on which methods to define.
Some short introduction to give an idea of what the webservice should expose: I am building domotica software (software that can control a ZWave network) which has different interfaces (a GUI application, a web server for configuration, and tablets/phones to control the network).
The webservice is the central application that : - has a controller that can interact with ZWave devices - exposes a WCF Json service so that clients can query and control on the ZWave network
The easy methods on the WCF interface:
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "getnodes")]
public List<Node> GetNodes()
{
// ... retrieve all nodes from ZWave Controller
}
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "getnode/{id}")]
public Node GetNode(uint id)
{
// ... retrieve specific node
}
What I was wondering, is how "specific" the API should be in terms of POST/PUT methods. Clients need to interact with nodes, like set the name, set the room where the node resides in, switch a node on/off, set a dim amount, etc, etc.
I defined one method as follows:
[WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json, UriTemplate = "setnodename")]
public void SetNodeName(NodeNewName nodeNewName)
{
// .. sets the name of the node, as specified in the passed object
}
This works, however this does cause a lot of different methods AND specific classes (as I specified a short list above of the functionality which would demand for specic methods and classes for each of them).
Is that the way to go? Or should I have one method UpdateNode and a more generic class as parameter which only specifies the properties that need to be updated? Or is there some kind of a guideline that would help me define a solid design for my webservice?
I googled a lot on this topic, and I read some articles about WCF design guidelines, but not really something where they cover this part. (or I am not the best googler on this specific topic, which would make sense as I am new on WCF/REST/Json/etc).
Hope somebody can understand what I am looking for and can help me on my way.
Much appreciated!
ServiceHostand define the interface and "voila". I didn't want to bother with IIS or other webservers, so it seemed like a good fit (plus I feel safe with C#.NET). For the nodes bit, the answer is yes. Stuff like names, manufacturer, type, location is default. Whether a node can be switched on/off, dimmed, measured, etc depends on the type of node (and thus are specialized properties). .PS: if WCF wasn't a smart move, please feel free to elaborate