AspNetCoreWebSocketTransport
esso23 opened this issue · 6 comments
Hi,
AspNetCoreWebSocketTransport is not working for me.
I tried configuring it based on these issues.
#179
#216
Here is my configure method:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
mHost =
new WampHost
(
new ForwardingRealmContainer("ws://10.8.0.250:50000/ws",
new TicketAuthenticator("Backend", "648g684g4864==[")),
new LooseUriValidator());
app.Map("/ws", builder =>
{
builder.UseWebSockets();
mAspNetCoreWebSocketTransport = new AspNetCoreWebSocketTransport(builder);
mHost.RegisterTransport(mAspNetCoreWebSocketTransport,
new JTokenJsonBinding(),
new JTokenMsgpackBinding());
});
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseMiddleware<AuthMiddleware>();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
}
First problem I found is that the connection is never opened, Open() method is never called so it keeps using EmptyHandler
. Do I need to open it manually, or should that be handled somewhere in WampSharp? When I force WebSocketHandler
in the constructor, it fails here (requests are properly sent from wss://xxx.xxx/ws to this handler):
IEnumerable<string> possibleSubProtocols =
context.WebSockets.WebSocketRequestedProtocols
.Intersect(this.SubProtocols);
string subprotocol =
possibleSubProtocols.FirstOrDefault();
because this.SubProtocols
is empty.
I noticed that in RegisterTransport of WampHostBase here:
if (bindingArray.Any())
{
mTransportDefinitions.Add(new WampTransportDefinition()
{
Transport = transport,
Bindings = bindingArray
});
}
the transport itself has no SubProtocols and empty mBindings after initialization.
At this point I stopped as there seems to be too many problems and I might be doing something wrong.
Any help would be appreciated
Esso
There are not enough details here, to debug this I need a full project that does not work. One common pitfall is to forget to call .Run()
if you construct the Host yourself, see this issue.
Elad
I just used the example in the issue I referred to, and it works fine.
If you're using IIS, you might need to enable WebSockets.
Elad
Oh my god, I can't believe I spent so much time on this :D
Thanks a lot
You need to enable IIS WebSockets.
Elad