I thought I'd start a discussion about the WCF Web API from the point of view of someone developing a website or mobile application. The use case is quite simple: Make an Ajax call to the service sending an optional JSON object and receive a JSON object
or an array of JSON objects in response. I am struggling to find anything useful in the WCF Web API. Here are my thoughts.
Media Type Processors
This is a way to return a different result type from a service call depending on the accept header. E.g. XML, JSON, or an image.
Problem: We only ever need JSON from the service. While it would be brilliant to serve up images from the server, it is not possible to influence the accept header when the browser makes a request for the URL specified in the src attribute of an image tag.
The JsonValue dynamic type as an input parameter and return value
The following example demonstrates usage:
public JsonValue Post(JsonValue contact)
var postedContact = (dynamic)contact;
var contactResponse = (dynamic)new JsonObject();
contactResponse.Name = postedContact.Name;
contactResponse.ContactId = nextId++;
Problem: While this is fine as a return value, we don't really want to work with loosely typed objects on the server side. Ideally the WCF pipeline should attempt to convert the input stream into whatever CLR type has been specified as the input parameter,
in a case-insensitive fashion, very much like how ASP.Net handles it. Ignoring case is important because JSON on the browser is generally camel case, while CLR types tend to favour Pascal case.
This appears to be a way of querying the service either by specifying URL parameters or using the HTTP client class. The latter is not relevant for the web, and there are better alternatives to the former, namely a more restful and
structured approach. The suggested technique of simply exposing the entire database through a single service call is not very appealing.
Not relevant for the web. Could possibly be used for inter-service communication.
HTTPRequestMessage and HTTPRespnseMessage
Possibly the only thing that is useful. This makes the service more testable. But surely this can be implemented via a WCF operation behaviour?
Request and Response Processors
These convert elements of a URI into CLR types. But really all we need is to convert JSON to CLR types. And that is already well-established.
Am I missing the point?