I'm making test in a Client Side Blazor app targeting Blazor 3.0.0-preview4-19216-03
The razor page:
@page "/counter"
@using BlazorServiceTest
@inject IWebCrawlServiceAsync WebCrawler
<h1>Counter</h1>
<p>Current count: @debug</p>
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
@functions {
string debug = "";
async void IncrementCount()
{
debug = await WebCrawler.GetWeb();
}
}
The dependency injection:
using BlazorServiceTest;
using Microsoft.AspNetCore.Components.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace BlazorServicesTest
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IWebCrawlServiceAsync, WebCrawlServiceAsync>();
}
public void Configure(IComponentsApplicationBuilder app)
{
app.AddComponent<App>("app");
}
}
}
The Service:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace BlazorServiceTest
{
public interface IWebCrawlServiceAsync
{
Task<string> GetWeb();
}
public class WebCrawlServiceAsync : IWebCrawlServiceAsync
{
private HttpClient _client;
public WebCrawlServiceAsync(HttpClient client)
{
_client = client;
}
public async Task<string> GetWeb()
{
var response = await _client.GetAsync("https://postman-echo.com/response-headers?foo1=bar1&foo2=bar2");
var result = await response.Content.ReadAsStringAsync();
return result;
}
}
}
Whenever I click in Increment count nothing happens and the service call to GetWeb
it's stuck in the GetAsync
call.
UPDATE
If I debug the service WebCrawler in Chrome's WASM debugger, he request is being made
But the response section is empty: