3

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

3
  • 1
    What do you do with the model object after setting the values? I am not sure I understand the purpose of doing this. Is it like two applications one which can create and other to display what was created? Commented Apr 24, 2015 at 7:08
  • Web API will be better option. Use web API to expose methods which can receive message and save them into database. Passing an object from console to web or between two independent application is not a good idea. Commented Apr 24, 2015 at 7:22
  • i suppose it doesn't matter what what to use. If i understand you correctly you iether way will sent yout message through http. so it doesn't really metter where you will store your information in ViewData or params of get request. Commented Apr 24, 2015 at 7:24

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This sure looks interesting, I will take a look into it. Thanks
Well, I have it working now. From console, the hub class is called. And the hub broadcasts to all the clients to update, and also calls my database helper class to add an entry to the database. However, I used a Gridview to display the data from the database (which requires refresh of the page, which was the whole point of SignalR instead) I was thinking to override OnConnected in the Hub class, and append all entries in the databases to the page when a user connects and after that use the original SignalR broadcast for no refresh Any thought?
1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.