连接时,带有SignalR的Xamarin android返回400状态代码

时间:2017-05-09 08:05:25

标签: c# xamarin.android signalr

我有用于android和Xamarin项目的Asp.Net Web Api项目。我想使用SignalR,但当我尝试从android ir连接返回400状态。

SignalR配置最小,断点在Configuration方法中被点击。

public void Configuration(IAppBuilder app)
{
    app.MapSignalR();
}

集线器类

public class MainHub: Hub
{
    public void Send(string platform, string message)
    {
        Clients.All.messageReceived(platform, message);
    }
}

在android项目中,我使用HubConnection和web api port 10.0.2.2创建65443

public class ServerCommunicationService
{
    private readonly string _platform;
    public readonly HubConnection _connection;
    private readonly IHubProxy _proxy;

    public event EventHandler<string> OnMessageReceived;

    public ServerCommunicationService(string platform)
    {
        _platform = platform;
        _connection = new HubConnection("http://10.0.2.2:65443");
        _proxy = _connection.CreateHubProxy("MainHub");
    }

    public async Task Connect()
    {
        await _connection.Start();

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

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

然而我收到错误

  

StatusCode:400,ReasonPhrase:'Bad Request',版本:1.1,内容:System.Net.Http.StreamContent,标题:       {           服务器:Microsoft-HTTPAPI / 2.0           日期:2017年5月9日星期二07:59:01 GMT           连接:关闭           内容类型:text / html;字符集= US-ASCII           内容长度:334       }

我错过了什么让它起作用?

0 个答案:

没有答案