How to connect ASP NET web app client with NET framework console app server - c#

I need to develop a NET Framework MVC web app that takes 5 items in a form, each one consisting in a description and an image. I need to post these to a server app (locally) that takes this data and stores it in an XML file for example (No need to use relational DB). My server app is a console based in NET Framework. When I change the description of the file in the server, I have to display in "real time" the updated values in the ASP NET web app in the client side, so somehow I need to send back the values of the file back to the ASP NET web app. I have been looking to signalR but seems to be more suitable for instant messaging rather than working with files, so I thought websockets would be a good idea. Doesn't seem too complicated but I have never worked with websockets so I wonder if this is possible to do with my suggestion above so I have a few questions:
Is it possible this flow of data between an ASP NET web app and a server console app? would it be better to create a web API in the server to handle this?
How can I send data from the client web app to the console, is via URL a good option?
Can anyone suggest a simpler or more feasible solution to this?
I much appreciate some help here.

I would choose building an API since you can send the updates whenever they change, no need to wait or keep connections open.
If you really have to send updates in realtime, SignalR combines different ways of keeping a connection open, so it could be the best option.
I prefer using SimpleTcp to easily establish a tcp communication between server (web app) and client (desktop or console) so this is also something you can consider.

SignalR already has websocket implementation. Your solution could be for example creating the signalR hub inside the console application and then using the webapp to connect to it. On either end you call a method that changes the other side.

Related

What is a proper way to communicate from my website to the .NET (C#) and vice-versa?

I'm using CefSharp as a webbrowser framework in a Visual Studio C# Form application project.
I read in the CefSharp documentation that I can communicate from the .NET to my website using CefSharp Javascript Injection.
chromeBrowser.ExecuteScriptAsync("document.body.style.background = 'red';");
This line of code will change the background of my document to red.
I'm pretty sure this is not a proper way to establish a communication from the .NET to the website. (I would want for example to send data that the .NET project has to the website so the website can update the MySql database and this seems like a very fragile way to do it)
So I continued to google and I stumbled upon this. It says it
allows for communication between JavaScript and .Net.
Fair enough. I tried to read and understand what's going on but it's quite complex.
My question is: Is this the proper way to establish a communication from my website to the .NET project and from the .NET project to my website? Is there a simpler way?
The thing you've shown is just a communication between JavaScript and .NET
To actually communicate with the website you should use:
Web Sockets: Real-time communication between your server and client.
HTTP: You can use usual HTTP requests in C# to send requests and receive responses.
JavaScript: Run the JavaScript code that will request stuff with CefSharp tools.

Socket.IO & Express alternative for C#?

I'm looking to see if it's possible to create an application using C# that creates a local web server and allows me to pass information from the server, to the client website.
I've been using Node.js with Express to create a local web server and then using Socket.io to pass information through to the client, to display in realtime with Javascript. Only issue is I'm more comfortable with C# and I'd like to distribute this application, with Node Modules and Electron the app is clocking in at around 150MB, it's also many files and folders as opposed to just a .exe
Details of Application:
Reads data from log files
Decodes Json inside files
Sends specific data to website
Client receives data and displays
I've managed to get halfway there by using HttpListener, but from what I understand I cant send data to it? So I figured I could edit the html before I sent it and have yet to setup the FindDivByID method
TLDR; Is there a way to create a Local Web Server (Application) that is able to send data to the Client Website.
EDIT: Thanks for the suggestion, though I'm hoping to keep it all down to one distributable application, that reads the data from the local PC, creates the web server and sends to the clients
Well, if you wanna go full C#, I'd recommend SignalR, very solid
https://www.asp.net/signalr
Alternatively, you could keep your Socket.IO server in Node.JS and use this Socket.IO C# client library to interface with it (although I never really did tried)
https://github.com/Quobject/SocketIoClientDotNet

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

Two way communication between asp.net application and windows application

Is it possible to have this type of communication using signalR: The two applications are not on the same machine I want the ASP.NET application sends some data to Windows application, Windows application makes some processing then sends data back to ASP.NET application.
Any ideas, how to acheive this?
Yes, you can use SignalR but you will need to set-up a server (using SignalR) that controls the flow of information between the applications. For more details, refer to the documentation here:
http://www.asp.net/signalr

Categories