Good Day Everyone
i have created a Asp.net Core web api for the purpose of SignalR
my hub is defined like this
public class ChatHub : Hub
{
public ChatHub()
{
}
public void SendMessage(string AUTHOR, string CHAT_MESSAGE, string model)
{
try
{
CHAT_MESSAGES_Model chanmessagemodel = Newtonsoft.Json.JsonConvert.DeserializeObject<CHAT_MESSAGES_Model>(model);
Clients.All.SendAsync("ReceiveMessage",AUTHOR, chanmessagemodel.CHAT_MESSAGE, model);
}
catch (Exception ex)
{
//
}
}
public async Task SendMessageAsync( string AUTHOR, string CHAT_MESSAGE, string model)
{
try
{
CHAT_MESSAGES_Model chanmessagemodel = Newtonsoft.Json.JsonConvert.DeserializeObject<CHAT_MESSAGES_Model>(model);
await Clients.All.SendAsync("ReceiveMessage",AUTHOR, chanmessagemodel.CHAT_MESSAGE, model);
}
catch (Exception ex)
{
//
}
}
}
and Program.cs looks like this
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
//services cors
builder.Services.AddCors(p => p.AddPolicy("corsapp", builder =>
{
builder.WithOrigins("*").AllowAnyMethod().AllowAnyHeader();
}));
builder.Services.AddSignalR();
builder.Services.AddResponseCompression(opts =>
{
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { "application/octet-stream" });
});
var app = builder.Build();
app.UseRouting();
//app cors
app.UseCors("corsapp");
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.MapHub<ChatHub>("/chat");
app.Run();
when i access the local host or the hosted URL (https://localhost:7054/chat
) for testing purposes , i get this error
Connection ID required
In using this in Xamarin like this
string serverurl = "https://myserver.com/SignalRChat";
hubConnection = new HubConnectionBuilder()
.WithUrl($"{serverurl}/chatHub")
.Build();
await hubConnection.StartAsync();
Receiving the message
hubConnection.On<string, string,string>("ReceiveMessage", (AUTHOR, MESSAGE, Model) =>
{
//Do work
});
and i get an error
Response status code does not indicate success: 404 (Not Found).
The error happens on this line
await hubConnection.StartAsync();
What could be the issue ?