Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to call a function in web page from windows application

I have an windows application and also web page application in two different solution and I want When any changes happen in windows application could automatically call "LoadData" method on web page so update page data. how should I do ?
web application is ".net core blazor"
window application is ".net framework c#"
best regards.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Your windows application has to make an http call to your web application using the HttpClient class check this https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

here is the code from the link, I adjusted the URL to the web application to point to your page

static readonly HttpClient client = new HttpClient();

static async Task Main()
{
    // Call asynchronous network methods in a try/catch block to handle exceptions.
    try 
    {
        HttpResponseMessage response = await client.GetAsync("http://you-site/your-page");
        response.EnsureSuccessStatusCode();
        string responseBody = await response.Content.ReadAsStringAsync();
        // Above three lines can be replaced with new helper method below
        // string responseBody = await client.GetStringAsync(uri);

        Console.WriteLine(responseBody);
    }
    catch(HttpRequestException e)
    {
        Console.WriteLine("\nException Caught!");   
        Console.WriteLine("Message :{0} ",e.Message);
    }
}

The line client.GetAsync("http://you-site/your-page"); will cause your-page to get loaded which will call the page_load function

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading