我试图在我的应用中实现聊天,后端使用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设备执行此操作时 - 它会在线上崩溃内部服务器错误(&#39;等待_connection.Start() ;&#39)
我已经使用调试器检查了服务器,但没有异常,并且日志清晰。
任何想法如何解决这个问题都会非常有用!
[ UPD ] 一些新的服务器日志:
FROM SIMULATOR:
2015年9月27日3时29分39秒IBYB GET / signalr /谈判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
FROM DEVICE:
2015年9月27日3点35分02秒IBYB GET / signalr /谈判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 11369 1676 281
所以,不知何故,不知道为什么设备发送空组名称 (1):[%7B%22Name%22:%22chat%22%7D] (2):[%7B%7D]
看起来像json序列化器问题,但我该如何解决?
答案 0 :(得分:3)
终于明白了,这是因为所有&#39;设备构建选项中的选项,因此json不能正常工作