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

我正在尝试在我的应用程序中实现聊天,后端使用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年9月27日3时29分39秒IBYB GET / signalr /谈判clientProtocol = 1.4&安培; connectionData = [{ “名称”: “聊天”}]&安培; 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年9月27日3点35分02秒IBYB GET / signalr /谈判clientProtocol = 1.4&安培; connectionData = [{}]&安培; connectionToken = YIZWqEe7AHvZHwb_aG7jOA9y_NFwUTBuLWSP46q8yh2rQMcjASbsp7VWlZ0Jzo_Z-n230IlhnOHZKm8kJr72ejLF-4LMopwyfZaWmsKNAy6cTd5uyU-76WoXsd2gpmpEJp8A0vMXe2HeLMIvH2Ckw6NIamEbu_uQvHRplkGeUhqGbTQU04dsU47ksebG_zh9XTtLGY9767CiwCYBg_Zk3aFgfrSvzPBiijfmIP9mUhz2ViAigyPeDeOE6WYRgtkkOIGMXGOoS5vQODHMUtiMaoV-W-jcCWtjHzzaObKNeX6zAsB0aJDc9_7fJAoBER7Jd6g0FOuEDvo8D95f1vA8j2SxbBgR4SFIzBDo_JfzO_TbPA6a2FR-ruw3yZHMidmcz3XQWb3vL5a0BPntzL9MPiVgvuhvkXfiRoDrRbzn2YXSqWrN-eEdjsF_WX-LMUc1JyKkjcHP00EAw3kocDWbnXaPqirsSvC5SZ7KY1u63BU&安培;非缓存= 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 11369 1676 281

所以以某种方式,不知道为什么从设备发送空的组名
(1):[{“名称”:“聊天”}]
(2):[{}]

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

解决方法:

终于明白了,这是因为设备构建选项中的“全部链接”选项,所以json不能很好地工作

上一篇:javascript-客户端的SignalR处理超时事件


下一篇:Nginx 服务器配置支持SignalR (WebSocket)