Building a remote command for Elpis in C# through HTTP API - c#

I am helping to build Elpis, which is an open source pandora music player, built with C# and WPF.
Now what i want is to add an HTTP API so that the user may control the program through a browser, like play/pause, like/dislike the current song.
The point afterwards is to control the program through a mobile device accessing the HTTP API.
How exactly should i build the HTTP API so that it can control it?
Github for the project: https://github.com/adammhaile/Elpis

Without knowing why exactly you want the user to control a GUI application via the browser, it's hard to give you good advise.
Assuming you are running your GUI on Windows, take a look at OWIN and the project Katana. They allow you to easily host HTTP interfaces in your own application.

It may be overkill for your project but I would suggest using ASP.NET Web API so that you can build backend web services.

The easiest way to do what you want, assuming you really want to "control the GUI remotely" is to just install TeamViewer on your PC and on your mobile device. Then you could remote in and completely control your GUI.
But I what I think you're after is something more like Google Music. Where you can stream your music through the Internet and onto your mobile devices. If this is the case, I recommend you look at the ASP.NET Web API.

It's not hard to build a web server in C#. You can embed it into your application, and expose parts of your application to HTTP endpoints as an API. You can use the HttpListener class which is part of .NET, and do everything from the ground up yourself. Or you could use something like Nancy, which is a lightweight framework that provides a lot of useful scaffolding like URL routing.

Ended up using Kayak(https://github.com/kayak/kayak) for my self-hosted API.
The example of integration can be seen here:
https://github.com/adammhaile/Elpis/blob/master/Elpis/WebInterface.cs

Related

Running web-application offline on android

A while ago I created an ASP.NET MVC Web Application for android devices. The application also used jQuery mobile to set up navigation etc.
At the moment, the application is simply being hosted and the androids webview accesses it that way.
The application works as expected, but I was wondering, is it possible to store the MVC web-app on the phone/integrate it into the apk?
I would like to be able to have it run the web-pages while the device is offline. I know it is possible to run simple HTML in the webview but I haven't been able to find anything about something like an ASP.NET MVC web-app. Is this done using phonegap?
Thanks.
I don't think you can do it directly with PhoneGap, from the PhoneGap FAQ
Q: Can you use PHP/ASP/JSF/Java/.NET with PhoneGap?
A: A PhoneGap application may only use HTML, CSS, and JavaScript.
However, you can make use of network protocols (XmlHTTPRequest, Web Sockets,
etc) to easily communicate with backend services written in any language.
This allows your PhoneGap app to remotely access existing business processes
while the device is connected to the Internet.
So if you are going the PhoneGap route, you'll have to write it in HTML/CSS/JavaScript. However if you more comfortable in .NET and C# then there is always Xamarin Android which has a free starter version that you can try out. Do realize though that if you go that route it will be a mobile app and not a wrapped ASP.NET app.
If I understand correctly I think what you want to do is serve your data via a web service (MVC4 web api is pretty simple to setup). Then you'd consume that data with your android app and you could more easily cache that data for offline use.

Looking to create a webservice for client authentication and need some advice

I am developing an android application to accommodate some desktop software that I created. I would like for the user of the mobile app to have to verify their identity through authentication. Basically the web service will have to act as a central hub to both authenticate and hold information that the android app will need. The way I think it should work is to
-Set up a central web service
-Allow user to create account from desktop client using email/password
-The desktop client will send the information to the webservice that the android app will need.
-when android app is authenticated it will then retrieve the data it needs that was posted from the client.
So basically the service will need to be able to send and receive data.
I will only be using .net (either C# or vb.net ) for the service, so this leads me to a couple of questions:
Should I be using WCF for this? If so should I create a WCF Service library or WCF Service application?
Should I be using the Sign Sign on service approach?
The web service doesn't need to be fancy it just needs to get the job done. Is their any boilerplate project templates or projects out their I could use to help build a foundation?
I recently discovered SudzC.com which generates classes and methods for Objective-C from the wsdl data of a .net web service, and I'm fairly sure it also does Android.
I have a huge catalog of fairly 'old' web services which pre-date WCF and they are currently working perfectly.
I should point out though that the SudzC service only shows you what it can do for you for free - to get the code you have to pay ~£20 for a one year pass.
We had something similar where I worked. We had to put together an Android app for the company. If you are on .net 4.0 or newer, you can take advantage of theWebApi. It can return json or xml. So, that means any platform can utilize it (desktiop, android, etc...). I found it extremely easy to use, with very little overhead.

Authenticated WCF Service for MonoTouch, Mono for Android and WP7

Iam writing a Phone App where the end user should be able to access their own personal messages and other personal content.
Does anyone have some good ideas of how to create a service like this, should i use Soap or Rest, should i simply send the username/password with every request or ?
What would be the best choice for a service i would like to access from all three platforms and that only returns information specific to the authenticate user.
As a suggested alternative to WCF that's at least worth taking a look at, ServiceStack, an open source REST Web Services Framework, is well suited for use in a mobile app and it supports the Mono platforms. It also has built-in support for user authentication. At the very least, it offers a JSON serializer that performs very well.
There's a Wiki for ServiceStack here.
I don't know what the support is like for MonoTouch / MonoDroid, but WCF supports secure services without adding username/password to every request manually (it actually does, but it includes it in the headers).
See this blog post for a great starting point for using WPF Custom Username/Password Validator: http://blogs.msdn.com/b/pedram/archive/2007/10/05/wcf-authentication-custom-username-and-password-validator.aspx

Control website via desktop application

Is it possible for a desktop application to communicate with a javascript API that will affect the user's browser? For example, I would like to call a JS API of a web service even if the browser is not in focus. The user can select various functions from within the desktop application and it will take effect in the browser. thanks
You probably want to consider automating the browser from your application. As you are using .NET, WatiN is a good option to do that:
WatiN
To get something like that to work you would need to have your web app call for updates on a regular interval and then make the appropriate changes.
Your desktop app can make requests to whatever web interface you wish to access data. It really depends on how you build it out.
Is this an existing app? Are you building something new? More info would be nice to have to get more specific.

Best Practices for Exchanging data between Desktop and Web Application

I have to pass information from a desktop application to Web application and vice versa.
What are the best practices that are regularly used?
Currrently I'm using Asp.Net and a Winforms.
To pass data to Web Site im creating a (POST) WebRequest and posting an xml to the site.
To pass data to Application im using .Net Remoting from Asp.net
(I'm using Winforms is an adminstration and monitoring application.)
Edit: Lets treat it as a generic web app and winforms.
Also currently both Web app and Winforms are on the same machine.(but can change).
Web Services or Windows Communication Foundation (WCF) would be your best bets for remote interoperability.
On your website, expose some service end points and consume them from your desktop app. Then send messages as you require.
I'd look hard at the design of the system and consider whether it's necessary to use a Winforms application at all for monitoring and administration. No, really: creating rich Web sites is quite straightforward (if necessary, with technologies like AJAX) and the architecture of the resulting application will be much, much simpler.
And, of course, deployment is then really simple.
I am not sure if there is a best practice for what you are trying to accomplish. There might be some security concerns you have to think about when allowing posts to your web application however. It would be very easy for a potential attacker to manipulate the post data and send it to your web application. You should consider using web services or Windows Communication Foundation.
Register a custom handler like how Real player registers rstp:// or for that matter web browsers register http://

Categories