I'm trying to implement SignalR Core in a .Net core 2.0
Web app, and implement client side in a Xamarin.Android
application.
I created a fresh .Net core 2.0 Web app solution and imported Microsoft.AspNetCore.SignalR
and setup the Startup.cs file like in this sample
https://github.com/aspnet/SignalR-samples/blob/master/ChatSample/ChatSample/Startup.cs
My code:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseFileServer();
app.UseSignalR(routes =>
{
routes.MapHub<ChatHub>("chat");
});
}
}
This project is deployed to Amazon Elastic Bean Stalk.
On the client side, I have imported Microsoft.AspNetCore.SignalR.Client
and I initialize a connection like in this sample
My code:
public async override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
hubConnection = new HubConnectionBuilder()
.WithUrl("http://*******.eu-central-1.elasticbeanstalk.com/chat")
.Build();
try
{
await hubConnection.StartAsync();
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.StackTrace);
}
}
But .StartAsync()
throws this exception:
{System.Net.WebSockets.WebSocketException (0x80004005): The 'Sec-WebSocket-Accept' header value 'LNqQiPhES/zOwW10TMji4AVvvoA=' is invalid. at System.Net.WebSockets.WebSocketHandle.ValidateAndTrackHeader (System.String targetHeaderName, System.String targetHeaderValue, System.String foundHeaderName, System.String foundHeaderValue, System.Boolean& foundHeader) [0x0002c] in <6c708cf596db438ebfc6b7e012659eee>:0 `
I found this post which was related to Amazon ELB and setting up websockets
(Elastic Beanstalk stripping Sec-WebSocket-Accept header)
Also found this post with same problem
(https://forums.aws.amazon.com/thread.jspa?messageID=613220)
As in this post, things are working fine if I choose "LongPolling" as transport
hubConnection = new HubConnectionBuilder()
.WithUrl("http://*******.eu-central-1.elasticbeanstalk.com/chat")
.WithTransport(TransportType.LongPolling)
.Build();
This guy was suggested to switch LoadBalancer listeners from HTTP to TCP, I tried this, but issue is still remaining Also I read a suggestion to install websockets in ISS on AWS Management Console, but I can't find this option anywhere?
Any kind of help or suggestions are appreciated