Designing a service for consumption on multiple mobile platforms
I am creating and designing (mostly) a read-only interface for some data. I will be using ASP.NET MVC to build a psudo-restful API. I am wondering if anyone can provide some resources for building fully functional apps for various mobile platforms, iPhone, Android, Blackberry, Windows Mobile, etc.
I think serving XML data would be the easiest and most versatile, but parsing XML in objective-C for example doesn't sound funny to me, but maybe there are some good libraries out there to make this easier?
In other words, which formt would be the fastest to implement on the client side? Are there any JSON parses for iPhone or Android? I know there are .NET JSON parsers, but not sure about other platforms - is this a different format, which could be better? Or should I stick with pure XML and deal with it differently on each platform?
a source to share
You can create a WCF REST service that provides results in both json and xml formats, and depending on the device, you can choose the format that best suits the capabilities of the device. It is also much better than creating and ASP.MVC's "pseudo-soothing API".
The WCF service will look like this:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(
Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "DoWork/xml/{ID}/{Filter}")]
void DoWork(int ID, string Filter);
[OperationContract]
[WebInvoke(
Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "DoWork/json/{ID}/{Filter}")]
void DoWorkJson(int ID, string Filter);
}
You can find a good example for creating a WCF rest service here.
a source to share
I have worked with parsing XML on an iPhone. If you're looking for a DOM parser, KissXML is the third party library that I suggest you go for. Its ease of use and performance is good. If you're looking for a stream-based parser, the NSXMLParser classes in the iPhone SDK are good. JSON is considered to be lighter than XML and therefore more mobile-friendly. There is a third party JSON parsing library for iPhone. You will need Google for these.
a source to share
stick to pure XML and deal with it differently on each platform
This is truly the only way forward. There is no magic cross-platform framework, and if it were, it would have been banned from the iPhone .
a source to share
If you have a really good reason to use XML, use JSON. The vast majority of web service responses can be adequately described using JSON, and there are several libraries (at least on the iPhone, I assume this is the same on Android and others) that allow you to parse JSON into your own data structures in 2 -3 lines of code.
On the iPhone platform, the json-framework makes it easy to parse JSON.
I guess the question is, assuming there is a JSON parsing framework for every client platform you use, what benefit do you get from using XML that justifies having to write more than three lines of code to parse? In most cases, there is no benefit.
a source to share
Use Json, all mobile platforms have Json parsers. For Android, this may not be the most efficient solution, but it is probably the most pragmatic.
Android natively supports XML, but not Json. In other words, what I'm trying to say is that Android phones are equipped with a hardware accelerator XML Parser (basically its own little piece of silicon), but when it comes to parsing Json, Android phones don't have that, so they have to use their processor to do this work. In theory, this would mean Android would use more CPU cycles, more power, and therefore more battery to parse Json than parse XML. That being said, doesn't fall into the trap of premature optimization, most likely whatever difference is likely to be negligible for your use case (and don't worry about it, just use your profiler once your application is finished).
a source to share