scotru wrote:
I recently finished a mobile app project for iOS and Android, LLBLGen was used for the ORM layer. I started of using oData but you have to use JSONP requests for that and it has severe limitations. If it's for a Java client I'd recommend a WCF Rest API or Web API approach and return DTOs/POCO classes serialized as json, works much better.
There's an even quicker approach I found on Frans asp.net blog
http://weblogs.asp.net/fbouma/archive/2012/11/04/llblgen-pro-and-json-serialization.aspx
Norman, could you speak more specifically to the limitations you encountered with ODATA/JSONP? I'm working on a very similiar project and am trying to make some decisions about SOA. (And also looking at ServiceStack.net).
Hi Scott,
Biggest issue we encountered with JSONP is error handling (or lack of), as our authentication service and data service were on different ports the browser effectively treats the calls as cross-domain. JSONP gets round this but essentially it won't return anything if your WCF service throws an exception like a 403 if your security key is invalid, This Ajax call show's what kind of error trapping you might want:
$.ajax({
type: "POST",
url: "https://www.myservice.com:8090/Myservice.svc/GetCustomer",
contentType: "application/json",
beforeSend: function (xhr) {
xhr.setRequestHeader('srv-authorization', localStorage.getItem('MyEncryptedKey));
},
data: JSON.stringify(e.dataItem.MyCustomerId),
dataType: "json",
cache: false,
success: function(msg) {
custfetchResponse(msg);
},
statusCode: {
400: function(jxhr, textStatus, errorThrown) {
app.hideLoading();
ModalViewNotify(APP_MSG2, "Data Service Error");
},
403: function() {
app.hideLoading();
ModalViewNotify("Your security key has expired or is invalid", "Security Error");
endSession();
}
},
error: function(jqXHR, textStatus, errorThrown) {
app.hideLoading();
ModalViewNotify("My Data service is not available at present, please try later", "Server Error");
}
});
With a JSONP call you can't trap these errors effectively, you have to do a hack that sets a timeout and trap that but you won't know why your service failed.
All modern web browsers use CORS, all the Android, iOS and Blackberry webkit browsers do and Chrome and they are the browser we support. Firefox does after a certain version and IE of course has it's own non standard approach but most modern browsers send a 200 (OPTIONS) request to the WCF service and you have to handle that.
CORS is the moderm approach so if I was starting a new project I wouldn't consider JSONP, also I'm not entirely sure where MS is going with oData, they dropped the Rest API and rolled it into WebAPI even though it's in the .NET4 framework. Also on a 3G connection or lower you have to really consider the amount of data your returning, we just found the performance of the Rest API far better (on UK mobile networks anyway).
We support native iOS, native Android and webkit browser, we've found this approach to be very robust and you still get data back even when you have a weak mobile signal, the less data you have to send over the wire the better IMO.
If your getting data from data service you don't host or control then JSONP is an option as you won't have any control over CORS domain issues.
If you want to chat about this I'm on LinkedIn, just send me an invite.
http://www.linkedin.com/pub/norman-mackay/0/22b/56
Cheers,
Norman.