Webservices and Server-Client Connection with Windows Phone in C# - c#

I have a local test server on my pc on which I already filled a MySQL database. Now I would like to receive this data with my Windows Phone app and represent the data.
Currently, I've made ​​it awkward. I have a PHP script on my server that represents the database. The app fetches the source code and parses it with the Html Agility Pack.
But this version is too complicated right? How can I do it better? I know something with webservices, but I do not know so much of them. Can someone explain to me in more detail? I heard from OData, but what should I do on my Apache Server and what should I do in my C# App? For the C# App there are examples. I feel so dumb because I really know nothing about web-services. And the most tutorials don't help me.

You can implement SOA (Service Oriented Architecture). You should have a look to WCF :
WCF Tutorial for beginners
The idea of web services is pretty simple. You store some services on a server (services = C# functions) and you consume them on your client (which is you windows phone app).

Related

C# silverlight application server

I am building an application that needs to connect to a server to send and retrieve data constantly.
at first i was going to use mysql, by mysql is far from what i want. using this would force users to connect to the database constantly.
CAN C# silverlight connect to a server and send a message?
here is an example to something in C# console, VERY similar to what i am trying to achieve
https://www.youtube.com/watch?v=9kcrTKj7Jpk
Any documentation would also be helpful.
To be more specific my server will be written with C# console, but i want my c# silverlight to send the message.
Yes.
CAN C# silverlight connect to a server and send a message?
Traditionally, the way that Silverlight has connected to a server to send a message is with WCF services. This still works well, but the other option is REST.
What you will need to do is write a layer (or use an ORM like Entity Framework) to persist data from whichever database platform you choose (MySQL or otherwise). Then you will need to write REST, or WCF services on top of this. You will then need to consume the services from your Silverlight application.
There are many articles on this if you Google. Here is one of the ones that comes up instantly:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=228
One thing you must consider with Silverlight, is that by default, Silverlight will only talk to the server that the Xap package is hosted on. So, if you need the Silverlight app to talk to a different server, you will need to set up and expose a clientaccesspolixy.xml from the server where the WCF/REST services are hosted. This is a stupid limitation that Microsoft made a big mistake on in the first place. Here is an article about it:
https://msdn.microsoft.com/fr-fr/library/cc197955(v=vs.95).aspx

How can I implement a C# server that receives JSON data and how to POST it?

I have a phonegap iOS app which has a form that, when submitted, it should post some json data to a server and get a response. I have to use C# on the server side and listen somehow when the json is posted from the form in the phonegap app, do some stuff with the data and then respond to the phonegap app. How can I implement the c# server and how should I post the data from my html form? I am experienced in c# desktop applications, but I am really new to everything related to web stuff. The ios app is running in an iphone simulator on a mac in my local network. I have searched for resources but I haven't been able to do this and have been trying for a while. I think I don't need the whole code, just advice on how to do it and what to use.
Any help will be greatly appreciated.
Thanks.
ASP.NET Web Api is exactly what you need. It's a framework for creating web APIs that receive and respond to requests coming through the web, which of course includes JSON data.
ASP.Net MVC and/or ASP.Net WebAPI are perfect for this. Check out the resources at http://asp.net.
The MS Web API won't help with writing a server.
You don't need to write your own server, but you can if you so choose.
Setup and run IIS.
Make a simple ASP.NET Web Forms application
Handle the Page_Load event
Read the value of your json from the posted data using Request.Form["json"]; or whatever you called your posted fields.
System.Web.Script.Serialization.JavaScriptSerializer will help to deserialize your json. Just make a class for your types. You'll have add a reference to System.Web.Extensions.
Publish your application to IIS.
I can highly recommend ServiceStack. It's highly testable, easy to host, and in my experience magnitudes faster than any of the MS web service platforms. Plus, as you don't state what platform your server is, ServiceStack can be hosted on both Windows and Linux systems.
https://github.com/ServiceStack/ServiceStack/wiki/Mono
https://github.com/ServiceStack/ServiceStack/wiki/Self-hosting

How can I determine what does my mobile application require?

I'm confused between native apps and web apps in the mobile context. I don't know if I go with native mobile development then do I need to know HTML, CSS, and JavaScript. If not then how can I make that app connect to database online for example?
If I want to build an application for chatting on mobiles. Something like WhatsApp! Will knowing a programming language (e.g. Java on Android and C# on Windows Phone) will be enough to build something like that? or what other components are necessary to add?
Native apps tend to be more recommended for android apps as they are faster as it is running what it was intended i.e. java code, html web apps tend to be slower.
For what you want to do, a chat app, then a native android app, (using java code) will probably work best then trying to do it as a web app.
You would need to learn about Http connections for your chat application. If you are accessing a database, such as MySQL, then you would need to have PHP code running on a web service where the Android app can access the database.
As an example, if your application, need to query the database, then you would tell the Android app to post to the web server running the PHP code. The PHP code would run the query on the MySQL database, and the result set should be json encoded and echo'd out, that way, Android will receive the json encoded content. Then you would need to decode the json to process what was returned in some way.
Hope this helps.
For android you will need to learn Java and XML, and if you want to make a chatting application for all or either platforms you must learn SQL, (including php).

MySQL with MonoTouch

I'm quite new at using Monotouch and I want to make an app that can connect to my personal MySQL server at home.
I know how to do it in VS2010, but is it possible in MonoTouch?
It will be really helpful if you have a example.
First, I am not sure if you can access a MySQL database directly from Monotouch or not.
However, even if you could, unless you are just using the database on your home network, it probably isn't a very good idea to expose your database to the internet.
I would suggest creating a web service using Visual Studio that performs all of the database interaction. You can then just expose the functionality that you need through the web service and use that web service interface from Monotouch.
Although there will be a bit of a learning curve to start with, this will definitely be a better long term solution.
My solution is to host an small server at Amazon Cloud, where i have both my web service and an SQL server running. An bonus to that it's quit cheap. From my iPhone App im using WCF communication.

Connecting C# Back-end with PHP frontend

I have a code written in C# I would like to use as the back-end of a site I'm building.
I would prefer not to build the site front-end in ASP.NET (which integrates nicely with C#), and to use PHP or Python instead.
Is that reasonable? Should I re-consider using ASP.NET?
How can I achieve that?
Just use asp.net mvc framework for the frontend instead of plain asp.net. It's easy to learn. And if you know php it will be easy to you undestand asp.net mvc.
I don't see the reasons if you are using c# backend use php frontend. For sure you can create service layer on c# and communicate with php through it, but it does not make sence for me.
You can do whatever you like. Personally i wouldnt use php because i dont know very much php.
But you can do it, you could expose a soap web service and there are libraries that will let php talk to it.
No one here will be able to tell you what you haven't already told us. Asp.Net will probably be easier because of how everything integrates and you can share classes etc - but that does not mean you HAVE to use it.
Both of them are fairly passive server side technologies that present html to browsers though. why do you need 2 servers?
You have to ask why you are doing it .. if you are playing and want to learn then of course you can do it just to see how it all works. But if you are on a commercial project then id suggest that you dont need both a php and a c# server ... or if you do perhaps you want to go asp.net for your web server and if you need another layer of services behind then use WCF if you want to go a microsoft route. Howver it is usually possible to host all services in the same IIs instance.
You can do this i have done this for a web site my self use a database server or files,
http://dtpgroup.co.uk/
Your C# application can connection to your store save the info it needs to then php can read them if it file just use a formatted file E.G
if your using Database php can connect to MySQL or MSSQL so your C# application can use MySQL if you know what your doing in C# if not and your more comfortable in php then use MSSQL (also php have the superior documentation )
I work in both frequently
Ugh, in normal instances, reading data with C# writing it to files and loading up with PHP sound slow, inefficient and down wright crazy. I believe these terms are being used wrongly.
Client Server - user machine - database great for private networks where you connect to the DB without going over the internet
vs n-Tier
Client - Browser programming html, css, javascript connects to middleware over the internet
Middleware - inside your firewall, connects browser to database could be called part of backend - php and C# are middleware languages
Database final (generally 3rd) tier
With php and c# you are creating multiple middleware layers
why why why would you do this for a web app pick one
now if you have a web app with PHP and sneakerware in house client server apps that are controlled ie shipping, accounting that are not exposed - maybe but you have added complexity that you would not need (generally)
Gary

Categories