I created default blazor server side app. Then added Microsoft.AspNetCore.SignalR.Client and ChatHub class. Then edited startup.cs file (add services.AddSignalR() and endpoints.MapHub<ChatHub>("/chatHub")) and index.razor page. Then run by IIS express. it is okey.
Then added docker support and run Docker host. it is not working. Because only don't work hub connection StartAsync method. How to run it? Help me?Thank you very much guys.
Error is:
An unhandled exception occurred while processing the request. SocketException: Cannot assign requested address System.Net.Http.ConnectHelper.ConnectAsync(string host, int port, CancellationToken cancellationToken)
HttpRequestException: Cannot assign requested address System.Net.Http.ConnectHelper.ConnectAsync(string host, int port, CancellationToken cancellationToken)
index.razor code:
@code { private HubConnection _hubConnection; protected override async Task OnInitializedAsync() { _hubConnection = new HubConnectionBuilder() .WithUrl(NavigationManager.ToAbsoluteUri("/chatHub")) .Build(); _hubConnection.On<string, string>("ReceiveMessage", (user, message) => { var encodedMsg = $"{user}: {message}"; StateHasChanged(); }); await _hubConnection.StartAsync(); // **DON'T WORK IN DOCKER HOST.** }}Docker file:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS baseWORKDIR /appEXPOSE 80FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS buildWORKDIR /srcCOPY ["BlazorApp1/BlazorApp1.csproj", "BlazorApp1/"]RUN dotnet restore "BlazorApp1/BlazorApp1.csproj"COPY . .WORKDIR "/src/BlazorApp1"RUN dotnet build "BlazorApp1.csproj" -c Release -o /app/buildFROM build AS publishRUN dotnet publish "BlazorApp1.csproj" -c Release -o /app/publishFROM base AS finalWORKDIR /appCOPY --from=publish /app/publish .ENTRYPOINT ["dotnet", "BlazorApp1.dll"]