由于服务器上的错误,SignalR 调用无法正常工作
SignalR invoke not working due to an error on the server
我正在 Unity 上开发 VR 游戏,SignalR 正在使用我的 Hub 中的所有方法。
问题是一种方法没有按预期工作。该方法应该在游戏结束时 return 一些关于游戏的信息,但我收到此错误:
Failed to invoke 'SessionReport' due to an error on the server.
但是如果我尝试在游戏开始时调用该方法,它会按预期工作。
这是 Unity 中用于调用我的方法的代码 'SessionReport'。
public async static void SendReportInfo()
{
HubConnection hubConnection = SignalRInitConnection.hubConnection;
if (hubConnection != null && hubConnection.State == HubConnectionState.Connected)
{
Debug.Log("SignalR: Method SendReportInfo invoked");
try
{
await hubConnection.InvokeAsync("SessionReport", MapStats.riskHistory, MapStats.scoreHistory, MapStats.envHistory, MapStats.difficultyLvlByEnv, MapStats.mapNameByEnv);
}
catch(Exception e)
{
Debug.Log("EXCEPTION SESSION REPORT:" + e.Message);
}
}
else
{
Debug.Log("SignalR: hubCon is ko for SendReportInfo");
}
}
这是我的 SignalR Hub 中的方法:
public void SessionReport(List<List<Risk>> riskHistory, List<int> scoreHistory, List<int> envHistory, List<int> difficultyLvlByEnv, List<string> mapNameByEnv)
{
//Insert into DB
Console.WriteLine("Nice session report there.");
}
当我在游戏结束时调用'SessionReport'方法时,仍然建立了与Hub的连接。
为什么方法 'SessionReport' 在游戏开始时有效,但在游戏结束时无效?
问题是服务器上的 class Risk 没有默认构造函数。没有构造函数,SignalR 无法复制从 Unity 发送到服务器上的对象的内容。
我正在 Unity 上开发 VR 游戏,SignalR 正在使用我的 Hub 中的所有方法。
问题是一种方法没有按预期工作。该方法应该在游戏结束时 return 一些关于游戏的信息,但我收到此错误:
Failed to invoke 'SessionReport' due to an error on the server.
但是如果我尝试在游戏开始时调用该方法,它会按预期工作。
这是 Unity 中用于调用我的方法的代码 'SessionReport'。
public async static void SendReportInfo()
{
HubConnection hubConnection = SignalRInitConnection.hubConnection;
if (hubConnection != null && hubConnection.State == HubConnectionState.Connected)
{
Debug.Log("SignalR: Method SendReportInfo invoked");
try
{
await hubConnection.InvokeAsync("SessionReport", MapStats.riskHistory, MapStats.scoreHistory, MapStats.envHistory, MapStats.difficultyLvlByEnv, MapStats.mapNameByEnv);
}
catch(Exception e)
{
Debug.Log("EXCEPTION SESSION REPORT:" + e.Message);
}
}
else
{
Debug.Log("SignalR: hubCon is ko for SendReportInfo");
}
}
这是我的 SignalR Hub 中的方法:
public void SessionReport(List<List<Risk>> riskHistory, List<int> scoreHistory, List<int> envHistory, List<int> difficultyLvlByEnv, List<string> mapNameByEnv)
{
//Insert into DB
Console.WriteLine("Nice session report there.");
}
当我在游戏结束时调用'SessionReport'方法时,仍然建立了与Hub的连接。
为什么方法 'SessionReport' 在游戏开始时有效,但在游戏结束时无效?
问题是服务器上的 class Risk 没有默认构造函数。没有构造函数,SignalR 无法复制从 Unity 发送到服务器上的对象的内容。