Last post Aug 29, 2016 06:23 AM by Chris Zhao
Aug 26, 2016 09:14 PM|mdehghani|LINK
hi everyone, sorry if the question is so basic! I already have an asp.net website running and it is connected to an sql database and works fine. recently I made iOS and android applications based on the website and the applications work offline and independent
of any database. now I want to retrieve a single value from the database by the application and i read that the right way to do it is to use a web service (like restful wcf). but I'm finding it surprisingly difficult to learn how to do it due to little resources
and i was wondering why shouldn't I just make an ordinary webpage that I can pass values to it and it returns the desired value for me as a string and I could get the app to consume the data. I can even format the webpage result in Json format using asp.net
methods. so whats the point in using web services for me? do they do anything more than returning data? or do I still have to use web services instead?
Aug 27, 2016 01:15 AM|Nataraj Gandhi Arunachalam|LINK
Why not try to use a Web API to provide you the JSON data? It is much easier to set up a web api than a restful wcf service. You can write a Get endpoint to return the data that you need and consume it from your android and iOS applications. Some references
to set up a web api,
Since you already have the data access logic in your asp.net website, use the same in your web api. So essentially, you only only need to write a controller and a get method. The data access logic can be copied or reused from your web application.
Aug 27, 2016 12:29 PM|mgebhard|LINK
Web services provide access to internal resources like database tables and business logic without needing to build UI. Users consume the service and build their own front-end. There is no rule that you must use ASMX, WCF, or Web API.
Aug 28, 2016 11:05 AM|mdehghani|LINK
Nataraj Gandhi Arunachalam
Why not try to use a Web API to provide you the JSON data?
thanks for your kind reply. I integrated a web api to my existing web-pages website using this tutorial:
but now i can't find an easy to understand way to deal with sql databases. i wonder why it's so difficult although i've made websites, android and ios applications so far :(
Aug 28, 2016 11:21 AM|PatriceSc|LINK
It won't change anything. You are in C# code and you'll just use the same way to interact with the db you used with your web application. Or do you mean from the client side ???
The idea is that from the client side you are doing htttp calls to read and write data and on the server side it is handled as usual with C# and the db functions you used already for your web app. For example if you used EF, see
Or maybe the problem is that you are using ADO.NET for which you'll find less tutorial with web APIs ?
Aug 28, 2016 12:00 PM|mdehghani|LINK
Aug 28, 2016 05:17 PM|mdehghani|LINK
It won't change anything. You are in C# code and you'll just use the same way to interact with the db you used with your web application
this is how i define a database in my website:
var db = Database.Open("LawCal");
where should i put it in my controller?
Aug 28, 2016 06:40 PM|mdehghani|LINK
i just forgot everything about API and stuff like that. just made a new .cshtml page, queried my data and used the Jason helper to display it as jason. what's you're idea now?
Aug 29, 2016 06:23 AM|Chris Zhao|LINK
But the tutorial i mentioned above only shows how to store or fetch data using lists and not databases.
You could visit below link, it will provide an overview of the ASP.Net WEB API and sample source code to get data from a table using the ASP.Net WEB API, MVC and jQuery.
Load Data From Database Using Web API
Get Data From Table Using ASP.Net WEB API