PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 11, 2022

[FIXED] how to call a function in web page from windows application

 November 11, 2022     blazor-webassembly, c#, httpclient, web-applications, windows     No comments   

Issue

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

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



Answered By - Siraf
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing