Integration between Console Application, Webservice and Frontend Web C#

Asked

Viewed 309 times

-1

I am developing my TCC and need guidance on how best to do some parts of the system.

Description:

It is a system for optimizing the use of laboratories. Such a system should have web frontend on the client side and a web service on the server side.

Frontend - simple system that should have a list of laboratories and some information, such information should be sent to the server through the web service. The frontend also have a "RUN" button, which should communicate to the server-side web service, the server will run the optimization algorithm and return the response to the frontend to be displayed to the user.

Server - should have a Rest API (or similar) for communication with the frontend. I already have a DLL ready with the definition of system classes, datacontext for entityframework and implemented optimization algorithm. The server side should run the optimization algorithm at predefined times and when clicking the "RUN" button on the frontend.

Problems I’ve been facing:

  1. I don’t know how to make the "RUN" button generate an action (run the algorithm) on the server side.
  2. I don’t know how to get the method to run the algorithm at times specific on server side.

I thought about implementing a state machine (as a console application) on the server to do this control of when to run the algorithm. But I don’t know if this is the best way to do this.

I am open to possible solutions to these specific problems, or even change the architecture of the system.

The only thing I can’t stop using is the DLL with the classes and methods for the algorithm, but I can make small modifications to it.

  • On your front-end side, you’re working with which javascript technology?

2 answers

0

By describing your problem you should use a scheduling library, such as the hangfire.

With the very own web application template mvc of visual studio you can create a page with the run button, calls via post a method on the server that will run the job. In addition, you can, at the start of the application, create the schedule to run the job at the predetermined times. In the hangfire documentation itself there is an example for creating the recurring job https://docs.hangfire.io/en/latest/background-methods/performing-recurrent-tasks.html

0

I don’t know if I understand your question exactly, but come on.

First point:

1-I don’t know how to make the "RUN" button generate an action (run the algorithm) on the server side.

Answer: You can implement a Webservice on the server, by clicking the Run button the View will call an action in the Backend that should consume the Webservice and return the result of your algorithm to the Frontend.

2-I don’t know how to make the method run the algorithm at specific times on the server side.

Answer: This question left me a little confused because I didn’t understand what the algorithm will run from time to time, but if it’s something like updating information, I think you could create a Console application yourself.

Use your own S.O scheduler to control the execution of time to time, since most Operating Systems implement this type of service and still provide good stability, such as checking if you have network to run the routine, if any error persists ect, it may save you a little work.

Note: Make your question a little clearer and I will try to help you as much as possible.


Here’s an example of how to call this action by View

<input type="button" value="Create" onclick="location.href='@Url.Action("Index")'" />

Remember that in MVC pages are not mapped as in Web Forms, MVC works with the concept that every URL calls an action, which may or may not return a View.

In this example I tried to be as simplistic as possible including using the Webclient for being simpler, since his doubt was on how to call the action.

I built a Ws where it returns me a vector of Strings in Json format, I recover the Ws Value and present in View.

//Controller

public ActionResult SuaView()
    {

        WebClient cli = new WebClient();

        string jsonRetur = cli.DownloadString("http://localhost:54119/api/default/consulta");

        JavaScriptSerializer js = new JavaScriptSerializer();
        var retorno = js.Deserialize<string[]>(jsonRetur);


        return View(retorno);
    }

At the View I treated the return like this:

//My View that was created solely to display the received values and nothing else

@model string[]
@foreach(string nome in Model)
{
   @nome @Html.Raw("<br />");

}

I hope I have helped you, if you have a more specific question with the implementation, create a topic and be as objective as possible that I will try to help you in the implementation.

  • point 1 - it’s just this part of generating an action in the backend that I don’t know the right way to implement.

  • ready 2 - I thought to use that same OS scheduler, I was just wondering if it was a good approach. Obg!

  • Are you using MVC or Web Forms? Will this server-side algorithm return what kind of information? A list of objects? The routine you want to schedule on the server side need not return anything correct?

  • 1- I intend to use MVC in the frontend. 2- Will return a string. 3- Will not return anything, will run and take internal actions.

  • I believe the above answer clears your doubt, maybe you have some doubt regarding some specific process, if that is the case I suggest you open a topic with doubt (if you do not find a solution to your problem)

  • Don’t forget to rate the answer positively if it has helped you!

  • Helped yes Thiago, I have classified however as I am new on the forum my answer is not counted, grateful !

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.