C# 信号器客户端在启动连接时引发错误
我试图让SignalR客户端从C代码工作,但我做不到。我得到了这个错误:C# 信号器客户端在启动连接时引发错误,c#,signalr,signalr-hub,signalr.client,C#,Signalr,Signalr Hub,Signalr.client,我试图让SignalR客户端从C代码工作,但我做不到。我得到了这个错误: "StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Transfer-Encoding: chunked Access-Control-Allow-Origin: * Cache-Control: private Date:
"StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Transfer-Encoding: chunked
Access-Control-Allow-Origin: *
Cache-Control: private
Date: Tue, 30 Jul 2019 11:54:07 GMT
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Type: text/html; charset=utf-8
}"
但它在jQuery中运行良好。这是我的代码:
我尝试了本教程:在服务器端,这也是我的启动文件代码
var config = new HubConfiguration();
config.EnableDetailedErrors = true;
config.EnableJSONP = true;
app.MapSignalR(config);
在客户端:
async void ConnectToSignlr()
{
try
{
HubConnection hubConnection = new HubConnection("http://localhost:8087/");
hubConnection.Credentials = System.Net.CredentialCache.DefaultCredentials;
hubConnection.TraceLevel = TraceLevels.All;
hubConnection.TraceWriter = Console.Out;
IHubProxy proxy = hubConnection.CreateHubProxy("ChatHub");
proxy.On<string>("chekroomstauts", (message) =>
{
//do something on your ui maybe?
Response.Write("hello you connected");
});
proxy.On("notify", (message) =>
{
Response.Write("hello you notify");
}
);
// connect to hup pro
await hubConnection.Start();
await proxy.Invoke("Join", "1000");
}
catch (AggregateException ex)
{
foreach (var errInner in ex.InnerExceptions)
{
//Debug.WriteLine(errInner); //this will call ToString() on the inner execption and get you message, stacktrace and you could perhaps drill down further into the inner exception of it if necessary
Response.Write(errInner + "</br>");
}
}
}
异步void ConnectToSignlr()
{
尝试
{
轮毂连接轮毂连接=新轮毂连接(“http://localhost:8087/");
hubConnection.Credentials=System.Net.CredentialCache.DefaultCredentials;
hubConnection.TraceLevel=TraceLevel.All;
hubConnection.TraceWriter=控制台.Out;
IHubProxy=hubConnection.CreateHubProxy(“ChatHub”);
proxy.On(“chekroomstauts”(消息)=>
{
//也许在你的用户界面上做些什么?
回复。写下(“您好,已连接”);
});
proxy.On(“通知”,(消息)=>
{
回复。写下(“你好,通知”);
}
);
//连接到hup pro
等待连接。开始();
等待代理。调用(“加入”、“1000”);
}
捕获(聚合异常)
{
foreach(ex.InnerExceptions中的var errInner)
{
//Debug.WriteLine(errInner);//这将调用内部执行选项上的ToString(),并获取消息stacktrace,如果需要,您可以进一步深入到它的内部异常
响应。写入(errInner+“”;
}
}
}
毫无例外,我只能猜测细节
也许“chekroomstauts”是一个输入错误,而您的服务器想要调用“checkroomstatus”
也许“加入”没有定义
问候
Bernd确保已启动并正在运行,并且您已在启动时对其进行了配置(对于.NET core web API),确保已100%启动并正在运行,并且我没有使用.NET core just.NET 5 HTTP 500错误意味着服务器出现问题-可能是异常。如果编写了服务器端,则调试服务器端并查找异常。