简体   繁体   English

无法从Xamarin.Forms应用连接到SignalR服务器

[英]Can't connect to SignalR server from Xamarin.Forms app

Here's my environment: 这是我的环境:

  • Visual Studio 2017 15.1, running on Windows 10, which runs in VM on MacOSX. 在Windows 10上运行的Visual Studio 2017 15.1,在MacOSX上的VM中运行。
  • In VS I installed API23 Android SDK. 在VS中,我安装了API23 Android SDK。
  • On MacOSX: Xamarin Studio 6.3 在MacOSX上:Xamarin Studio 6.3
  • Both, XS on Mac and VS on Windows have Xamarin.iOS 10.8.0.175 Mac上的XS和Windows上的VS都具有Xamarin.iOS 10.8.0.175

I have one solution where I implemented signalR server. 我有一个实现SignalR服务器的解决方案。 It's a simple chat server. 这是一个简单的聊天服务器。 It works. 有用。 It's running on the windows VM. 它在Windows VM上运行。 I tried connecting and sending message from my mac (so technically a separate computer in the network) and it works! 我尝试从Mac(因此从技术上讲是网络中的另一台计算机)连接并发送消息,并且可以正常工作!

Now, I'm trying to consume it from Xamarin.Forms iOS and Droid projects.. without any success. 现在,我试图从Xamarin.Forms iOS和Droid项目中使用它。 In PCL 's App class I have: PCL的App类中,我有:

    protected override void OnStart()
    {
        // Handle when your app starts
        try
        {
            var hubConnection = new HubConnection("10.0.1.58:49919");
            var chatHubProxy = hubConnection.CreateHubProxy("ChatHub");

            hubConnection.Start();
        }
        catch (Exception ex)
        {
            // System.UriFormatException: Invalid URI: The URI scheme is not valid.

        }
    }

System.UriFormatException: Invalid URI: The URI scheme is not valid. System.UriFormatException:无效的URI:URI方案无效。

What am I doing wrong? 我究竟做错了什么?

Try a http:// prefix and another thing to try is to end a trailing slash. 尝试使用http://前缀,另一种尝试是结束斜杠。

So try combinations of: 因此,请尝试以下组合:

new HubConnection("http://10.0.1.58:49919");

new HubConnection("http://10.0.1.58:49919/");

new HubConnection("10.0.1.58:49919/");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM