I'm creating my first android app. My app works in the following way:
User log into the app.
The login details is on an online server which is SQL Server 2008 R2
The server will return data to the app and the data the data will be stored on the app's database.
The problem I am facing is how should i connect to Sql server database. I researched on this topic and found out that I need to use some service. Can someone suggest as to what service should i use? A normal .NET web service, WCF service or Java Service.
I also need to know how to consume this service in my app.
Softwares I have with me:
Visual Studio 2008
SQL Server 2008 R2.
Android Development Kit & Eclipse
SQLite
Please help me.
I highly recommend the Asp.Net Web API for this:
"ASP.NET includes ASP.NET Web API for creating rich REST-ful Web Services that return JSON, XML, or any kind of content the web supports! ASP.NET Web APIs can provide data services to mobile apps like Windows Phones, iPhones, Android and more. ASP.NET Web APIs can be used in any ASP.NET Web Application, including ASP.NET MVC, Web Forms, or Web Pages – it's all One ASP.NET."
http://www.asp.net/web-api
Just to get you the general overview here;
You do not connect your (Android) app directly to the remote SQL database/server. Android, nor any other mobile platform, provides a steady and reliable interface for doing so.
Secondly, what you want to make indeed is a (REST) web-service.
As long as your needs are simple (passing along a bit of simple data between your app and your database) this means nothing more then having some web language take up some GET or POST variables and putting them in the database for you. And the same the other way around.
You can do this in any (web)language. The choice for language might be most influenced by the server you want to run in on, and what languages it already supports.
Related
i want to build an android application and i need to save and retrieve data from sql server database
so i need to do that with web service
i dont have knowledge in web services and how they are done
so can you help me what is the best way to do the web service and connect my android client with sql database
That's a pretty broad question, but here are the basics. A web service is a program or app that runs on a web server, usually exposed to the internet, or within a company's LAN on their intranet. Web Services can be built using ASP.NET or JAVA or PHP. I've used ASP.NET, specifically Web API 2.0, and Entity Framework. Entity Framework makes it very easy to connect your Web Service to your SQL Server database. With Web API and Entity Framework, you can create your web service and connect it to your database with basic Read/Add/Update/Delete capability in 1-2 hours.
Once you write your web service, you need to publish it on a Web Server as a Web App. I typically publish to an IIS Web Server (also Microsoft). For that you need a Website Hosted account with a Microsoft based server. Microsoft can host your Web Service using the Azure Cloud service. You can check out some tutorials for building your Web Service using the technologies mentioned and deploying to the Web using Azure. You can get a free Azure account to start with. Then, if you need to use it for a long time, you might need to pay for hosting fees.
This is probably the easiest and best way for you to get started, particularly if you are new to web services.
Good Luck!
Here is a tutorial using the technologies I've mentioned, except for Azure. But you should be able to find a tutorial for publishing a web service to Azure separately.
https://www.c-sharpcorner.com/article/asp-net-web-api-crud-logics-using-entity-framework-without-writing-single-code/
I'm planning to write up an android App that will collect some data from a smartphone and periodically send the data to some publicly accessible machine (i.e., the machine has a public IP address). What is the best approach to doing this? Is there any good sample code or skeleton available online?
At this point the communication is one way, i.e., from smartphone to external machine.
HTTP is the ideal solution for an application like this. Run a web server on the external machine and POST data from the app to the server.
Info on how to do this from Android can be found here: How to send a data to a web server from Android.
As for the web server side of things, there are a ton of different solutions available. It all depends on your level of knowledge, what languages you're familiar with, and what you intend to do with the data once it arrives.
CGI is the classic web server tool for handling POST requests, but there are better techniques now. For example, the Java Servlet API if you like Java, WSGI if you like Python, PHP is a common server side language also.
can we pass data from mobile phone application (iPhone app / Android app) to ASP.NET website application?
Does it need to be on a secure channel like SSL?
ASP.NET website, I was thinking of having a WCF service to get data from the mobile phone application, but what would be the better data format?
REST? Json? Plain text?
If you host a WCF service, then the natural choice would be SOAP. In that case, you don't have to care about the format at all, as the code for calling your web methods will be generated automatically if you use an appropriate SOAP library. See this SO question to get some ideas for iOS and this question for Android.
SSL is normally a good thing to have, especially when you care about your users' security (which you should).
I intend to write a multi platform smartphone app (currently only I-phone and android).
Which has to send and recieve information from a web server I intend to create.
The web server will do all the algorithms, and handles also DB connection.
My question, is how is this best accomplished, which kind of web-server technology fit best the scenario, and supports connections from various devices.
Basically, I thought about implementing a simple TCP/IP protocol, making the app (on the phone) the client, and server on the web on the other side. however, I want to deploy the application to an application server (maybe google app, JBOSS, etc.) and I don't want to be stopped by various firewalls.
does anyone has an idea ?
edit: few things are certain, the application server will be written in java, and db will be mysql.
This is a very broad question and any suggestion about which backend technology to use will depend on your language preferences, your other requirements, etc.
For starters, I'd suggest JSON over HTTP as a transport mechanism: it's easy to parse on both client and server-side, and it's directly usable in Javascript should the need arise. XML is another choice, but it can be annoying to parse.
JSON-over-HTTP (or XML) will be completely device agnostic and won't have the firewall/proxy problems you'll run into trying to do a custom-implemented TCP-based protocol.
For the backend, may folks use MySQL or Postgres for their database, and connect to it from Java, C#, Ruby, PHP, or other server-side languages. Use what you're comfortable with or what you want to learn next.
Why not write the server-side as a regular web application - in whatever technology you like (php, asp.net, java)? This way you can deploy the app on any web server and your client apps on the phones would simply establish a connection to an HTTP server. Normally, firewalls would not be a problem in such situation.
I have used this setup for my apps (both android and iphone) - connecting to a web server app written in php with postgres back-end.
I am trying to develop a system that involves a:
server with a database that will handle the system's logic and manipulate data
an android app that will interact with that server (pull and push data into the server)
a website that will do the same as the android app, but from a website with slightly different data.
What I thought of is to use SQLite with Apache Tomcat installed on the server and deploy a Grails war file on it. That will take care of the 'website' side of the system. But what about the android app? Can it communicate with Tomcat as well?
Tomcat will suit your needs. I would look at hosting options though. Are you hosting your own server, or do you have a hosting provider? Do you have experience hosting a tomcat server etc. Do you have experience with java web applications, or other web frameworks? All of the above, and probably more should lead you to your decision on what type of framework/language to use on the server. This in turn will lead you to your options for hosting, and web-container to use.
Once that is determined all major web frameworks will allow you to publish web-services Rest, Soap, etc. that can be consumed by an android application.
Also, if you are planning on providing a web interface and service at the server level, my guess is you are going to be storing a fair amount of data, I would look into a more robust and scalable database such as mysql or postgres. This post contains some insights into this.
If you have an API that is web accessible, an Android can access it.
Android shouldn't have any problems communicating with Tomcat.
Look at http://grails.org/doc/latest/guide/13.%20Web%20Services.html for more information.
A RESTful web service is most likely what you'll need. Android can consume SOAP web services but it requires more work for less overall functionality.