gpt4 book ai didi

c# - SignalR .Net 客户端在设备上失败并出现 500 服务器错误,在模拟器上工作正常

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:42 28 4
gpt4 key购买 nike

我正在尝试在我的应用程序中实现聊天,后端使用 azure asp.net web api,前端使用 xamarin ios。

因此在后端,我使用以下行配置我的集线器:

        var hubConfiguration = new HubConfiguration();
hubConfiguration.EnableDetailedErrors = true;
app.MapSignalR("/signalr", hubConfiguration);

这是我的中心源:

[HubName("Chat")]
public class Chat : Hub
{

public Task JoinRoom(string roomName)
{
return Groups.Add(Context.ConnectionId, roomName);
}

public Task LeaveRoom(string roomName)
{
return Groups.Remove(Context.ConnectionId, roomName);
}

public Task Send(string message, string room)
{
return Clients.OthersInGroup(room).addMessage(message);
}
}

在 xamarin ios 客户端上,一切也都非常简单:

[Preserve(AllMembers=true)]
public class Msg
{
public string txt { get; set; }
}

public class Client
{
private readonly string _userName;
private readonly HubConnection _connection;
private readonly IHubProxy _proxy;

public event EventHandler<string> OnMessageReceived;

public Client(string userName)
{
_userName = userName;
_connection = new HubConnection("http://mywebsite.azurewebsites.net/");
_connection.ConnectionToken = NetManager.Instance.token.access_token;
_proxy = _connection.CreateHubProxy("Chat");
}

public async Task Connect()
{

await _connection.Start();

_proxy.On("messageReceived", (Msg platform, Msg message) =>
{
if (OnMessageReceived != null)
OnMessageReceived(this, string.Format("{0}: {1}", platform, message));
});

Send("Connected");
}

public Task Send(string message)
{
return _proxy.Invoke("Send", _userName, message);
}
}

因此,如果我从 ios 模拟器连接到服务器 - 它工作正常,但是当我尝试从我的 ipad 设备执行此操作时 - 它崩溃并在线出现内部服务器错误('await _connection.Start();')

我已经用调试器检查了服务器,但没有出现异常,日志也很清楚。

任何解决此问题的想法都会非常有帮助!

[更新]一些新的服务器日志:

来自模拟器:

2015-09-27 03:29:39 IBYB GET/signalr/negotiate clientProtocol=1.4&connectionData=[%7B%22Name%22:%22chat%22%7D]&connectionToken=1qZRVTwNMqgGiI8iPpJ9oaPPCeLhHti3UXZR4HYsw2_7SGzOj44WRt8qzBFPRELZu6zk33-8uS7MNaq5K7N5qA2BR1IgzUf8CP9ihoGbjcwtXpFkdyh5gNqFBTHIRSgc2yto5_AOGUok_opd4B9FjAmOhgQlHF_myf28oBBYJxaXZ5iJOXFpI33k6pmQASRvveW-kBRX_89BF2mxAqFkZmVh3_MCo2gWP-NRZZFtMd8ZoxYHnGhyGNVsiiN1KaTHB1xAakP7HZjLpWg7SigfMvtKW0g3eXBsAr1wCJsAKIRjCaMAQFGV0BkKfYztRXvz4QbSXmIBXpKtviYamOqih4-LQJyywwVNh_Djt9H0wYIZmVO565G4ZNKzQfSkK6jMFQz6GfFf_OSlUJIz -0IXsQ7t2kP5VfqVrRu5KK7pyqtZJE5Y4HikRkh6DP8GIYBiXZclmBrpwWhUYVq5P3J2zhDYDNW2GiB95xnRjzXSjPQ&noCache=ccc35de3-5b7a-49ac-bf89-f15145d2634f&X-ARR-LOG-ID=bce175df-8246-4e75-8887-707a7386e1ee 80 - 89.179.240.94 - - - ibyb.azurewebsites.net 200 0 0 942 1718 1093

来自设备:

2015-09-27 03:35:02 IBYB GET/signalr/negotiate clientProtocol=1.4&connectionData=[%7B%7D]&connectionToken=YIZWqEe7AHvZHwb_aG7jOA9y_NFwUTBuLWSP46q8yh2rQMcjASbsp7VWlZ0Jzo_Z-n230IlhnOHZKm8kJr72ejLF-4LMopwyfZaWmsKNAy6cTd5uyU-76WoXsd2gpmpEJp8A0vMXe2HeLMIvH2Ckw6NIamEbu_uQvHRplkGeUhqGbTQU04dsU47ksebG_zh9XTtLGY9767CiwCYBg_Zk3aFgfrSvzPBiijfmIP9mUhz2ViAigyPeDeOE6WYRgtkkOIGMXGOoS5vQODHMUtiMaoV-w-jcCWtjHzzaObKNeX6zAsB0aJDc9_7fJAoBER7Jd6g0FOuEDvo8D95f1vA8j2SxbBgR4SFIzBDo_JfzO_TbPA6a2FR-ruw3yZHMidmcz3XQWb3vL5a0BPntzL9MPiVgvuhvkXfiRoDrRbzn2YXSqWrN-eEdjsF_WX-LMUc1JyKkjcHP00EAw3kocDWbnXaPqirsSvC5SZ7KY1u63BU&noCache= daae80e6-d209-42c9-8780-35d00fd8208c&X-ARR-LOG-ID=b1aad3d6-7df8-4828-a89c-665d8b550c0c 80 - 89.179.240.94 - - - ibyb.azurewebsites.net 500 0 0 116不知何故,不知道为什么从设备发送空组名(1) :[%7B%22Name%22:%22chat%22%7D](2) :[%7B%7D]

似乎是 json 序列化程序问题,但我该如何解决?

最佳答案

终于明白了,是因为设备构建选项中的'link all'选项,所以json没有很好地工作

关于c# - SignalR .Net 客户端在设备上失败并出现 500 服务器错误,在模拟器上工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32686191/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com