Expose sql database as a web service for access from android phone
I have created two EditText fields and 开发者_JAVA百科a single submit button in Android using Eclipse. Now I need to develop a web service preferably in .NET that would expose my database. I must say that I did see this [http://www.hanselman.com/blog/CreatingAnODataAPIForStackOverflowIncludingXMLAndJSONIn30Minutes.aspx] before posting but I do not have knowledge of how to use a WCF service and instead I would prefer REST or SOAP.
I now just need to call the webservice on click of a button that would get a list of values of a particular column of the database in a ListView with a checkbox on emulator of Android
Please can anyone tell me how should I go about doing this ?
Thanks
EDIT:
Given your note below, I would skip the "...synchronize an SQLiteDatabase..." part of the background service on Android (as there doesn't seem to be anything to synchronize or cache on the target Android device). I would make that background service directly call your web service.
The important thing here is to perform the actual HTTP-request from your Android application in a worker thread. If you call it from the UI-thread (a.k.a. the default- or main thread) the web service will most likely not answer quickly enough to keep the application alive and Android will treat it as a non-responsive application.
An Android Service
will by default run in the same thread as the caller runs in (which most likely is the UI-thread). You could have a look at IntentService
which manages all the threading for you.
But before all this I think you need to design your database and sort out your web service. Unfortunately I'm a bit too rusty on Microsoft's products in order to provide you with useful help. But I figure there must be tons of tutorials and "how-to"'s out there.
ORIGIN:
Wikipedia has a suprizingly good definition of what REST should be about. This concept also maps very well to the Android ContentProvider
's concept.
Assuming that you want to expose a database on a web server I think I would write a simple REST based web service (on your web server) which gives you access to the tables and columns needed by the app (no more, no less).
By default I would perhaps continue with writing a background service (on Android) that periodically would synchronize an SQLiteDatabase (still on Android), maybe through a ContentProvider (NOTE that ContentProviders
aren't the only way to communicate with a database, actually I would even say that communicating with a database isn't even the main feature of a ContentProvider
).
Finally I would broadcast a notification (still on Android) when the synchronization ends so that any (Android) clients would know when to automatically request fresh data from the SQLite database. Perhaps this fetching of fresh data could also be triggered by pressing a button in the UI in order to allow the user to trigger a manual update as well.
If you write more about your Android App and what it's supposed to achieve I will modify my answer to be more correct and specific.
精彩评论