简体   繁体   中英

Send data from console application to asp.net website

I am quite new to C# and .NET and I have started working on a small local application.

In one visual studio solution, I should create a website than can retrieve messages written from a console application and display / store them in a database.

I was mostly wondering if there is any "preferred" way of doing it.

At the time, I have come up with two possible ways of doing it I think.

The first method Console Application CA References Website MVC Application WA which has a model class called Message. (it is simply a message i want to transfer)

When a user inputs text into a command line and hits enter, a new Message is created with that text. From there, I was thinking to use the <% ViewData["Variable"]%> to pass the information. Is this a good way of doing it?

The second method which I has not tested yet: My initial thought was to create a http connection and send a POST request to the website. I briefly read about creating a Web API application that would handle this.

Is there any other "standard" or preferred ways of solving the task?

I am looking for an efficient way of doing it along with testability.

/ If anyone ends up here, you can check out the result of this / https://github.com/egenvall/ConsoleToBrowser

I would suggest you to go through SignalR

http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr

  1. You have to build a service which should be exposing the content of the console

  2. From your web application use SignalR to invoke the service. This will display the data sent from the service on the screen without having to refresh the user screen.

    When you invoke the service it should bind the data to the screen and also save it to the database.

You can use GET method to send the data from console, open port 80 on your web server and send:

GET /page.aspx?id=12&data=test HTTP/1.1<line feed>
Host: your.domain.com<line feed>
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)<line feed>
<line feed>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM