У меня есть простое приложение для push-уведомлений SignalR, и я должен разместить его в Azure, оно отлично работает на моем локальном хосте, но в Azure оно не работает.Ниже приведен код.это решение Microservice, поэтому некоторые из настроек связаны с microservice.
public class Startup
{
private const string SwaggerApiVersion = "v1";
private const string SwaggerApiTitle = "Messaging Microservice API";
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddMvc();
services.AddAuthentication("BasicAuthentication")
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
services.AddScoped<IAuthenticationRepository, AuthenticationRepository>();
Utility.Swagger.SwaggerConfig.ConfigureService(services, SwaggerApiVersion, SwaggerApiTitle,
Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"));
services.AddSignalR();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
Tracking.SetConfiguration();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());
app.UseAuthentication();
app.UseSignalR(routes =>
{
routes.MapHub<NotificationHub.NotificationHub>("/notificationHub");
});
app.UseMvc();
Utility.Swagger.SwaggerConfig.ConfigureApplication(app, SwaggerApiVersion, SwaggerApiTitle);
Tracking.TrackEvent(Assembly.GetEntryAssembly().GetName().Name + ".Started");
}
}
Ниже приведен класс концентратора.
public class NotificationHub : Hub
{
public async Task SendMessage(List<string> userIds)
{
await Clients.All.SendAsync("ReceiveMessage", userIds);
}
public async Task SendToAll(string name, string message)
{
await Clients.All.SendAsync("SendToAll", name, message);
}
}
На самом деле соединение не устанавливается с моим клиентом реакции, и я не являюсьвозможность вызывать методы-концентраторы (SendMessage, SendToAll).
Ниже приведен код реакции клиента.
componentDidMount = () => {
let url = Config['MessagingMicroservice'].replace(/\bapi\b(?!.*?\bapi\b)/, 'notificationHub');
const hubConnection = new HubConnectionBuilder().withUrl(url).build();
this.setState({ hubConnection }, () => {
this.state.hubConnection
.start()
.then(() => console.log('Connection started!'))
.catch(err => console.log('Error while establishing connection :('));
this.state.hubConnection.on('ReceiveMessage', (userIds) => {
const usrIds = `${userIds}`;
if (usrIds.includes(this.state.userId)) {
this.getNotificationCount(this.state.userId);
}
});
});
};
И я получаю ошибки ниже.
WebSocket connection to 'wss://isambard-dev.capitawfm.co.uk:19081/IsambardServiceFabric/MessagingMicroservice/notificationHub/?id=OcLN9AYHOVp8Hr4t3mPVPA'
failed: Error during WebSocket handshake: Unexpected response code: 504
https://isambard-dev.capitawfm.co.uk:19081/IsambardServiceFabric/MessagingMicroservice/notificationHub/?id=jcEzEb0coVTp51hQeFlzOw
Error: Failed to start the transport 'ServerSentEvents': Error: Error occurred