This is the third installment about using and accessing RESTful webservices on the iPhone.
There is no example project associated with this post.
[ADO.NET] Data Services is Microsoft's way of turning EDM into web services. While researching the best way to access data stored in an SQL Server database from the iPhone, we decided to give Data Services a go around. Superficially it matched our broad criteria for the project's services layer:
- RESTful Interface,
- JSON payload support,
- Run on IIS,
- Easily access SQL Server
Accessing it on the iPhone turned out to be very simple. After it was accessible via a browser I began working on displaying a simple table from the database. I created the first version of RestConnection and I was able to get a list of data primitives out of the database and displayed in a UITableView in about an hour.
Atom is the default format for Data Services. You can specify JSON by setting the Accept header on your HTTP requests. JSON is much easier to deal with on the iPhone because of it's simpler format. However, if you have a good Atom handling methodology than that format maybe preferable.
Data Services has great functionality out of the box. Query options provide the ability to sort and filter result sets. The main thing that is missing is the ability to get a scalar value representing the results set (record/page counts). This has been addressed in the 4.0 version of the framework and will be available as part of the VS10 release (in beta already). See $inlinecount and $count for more information.
If you do a GET on the base service URL, it will return a service document. This xml contains information about the entities that are exposed via the Data Service.
If you append a /$metadata to your base service URL, you will get back an XML document containing Data Service Metadata. This information can be extremely useful for introspecting your Data Service. For example, it can be used in generating code to create a strongly typed business object.
This post has talked about ADO.NET Data Services and provided some useful links to get the basics down. Next time a coding example will show how to connect to a Data Service and parse the information, reusing and building on previous examples.
The next article can be found here.