Integration between Console Application, WebService and Frontend Web C #

0

I'm developing my CBT and I 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 should also have a "RUN" button, which should communicate to the server side web service, the server will execute the optimization algorithm and return the response to frontend to be displayed to the user.

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

Problems I've been experiencing:

  • I do not know how to make the "RUN" button generate an action (rotate the algorithm) on the server side.
  • I do not know how to make the method run the algorithm at times specific on the server side.
  • I thought of implementing a state machine (such as console application ) on the server to do this control when running the algorithm. But I do not know if this is the best way to do it.

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

    The only thing I can not stop is the DLL with the classes and methods for the algorithm, but I can make minor modifications to it.

        
    asked by anonymous 30.09.2017 / 02:15

    1 answer

    0

    I do not know if I understand your question exactly, but come on.

    First point:

    1-I do not 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 on the Run button the View will call an action in the Backend that should consume the WebService and return the result of its algorithm to the Frontend

    2-I do not know how to get the method to run the algorithm at specific times on the server side.

    Answer : This question made me a bit confused because I did not understand what the algorithm will run from time to time, but if it is something like updating information, I believe you could create a console application yourself .

    Use your own OS scheduler to control the execution from time to time, since most operating systems implement this type of service and still provide good stability, such as checking if you have a network to run the routine, should it occur some error persist ect, this can save you some work.

    Note: Leave 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 from the 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, even using WebClient because it was simpler, since your question was how to call the action.

    I built a Ws where it returns me a Strings vector in the Json format, I retrieve the Ws Value and present it in the 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);
        }
    

    In View I treated the return like this:

    // My View that was created solely to display incoming 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 doubt with the implementation, create a topic and be as objective as possible that will try to help you in the implementation.

        
    30.09.2017 / 17:55