首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法连接集线器

无法连接集线器
EN

Stack Overflow用户
提问于 2014-02-22 03:31:01
回答 1查看 230关注 0票数 0

在我的服务器端,我只有一个简单的MVC服务器端。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <directoryBrowse enabled="true" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

代码语言:javascript
复制
public class Chat : Hub
{
    public void Send(string platform, string message)
    {
        Clients.All.messageReceived(platform, message);
    }
}

代码语言:javascript
复制
public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.MapSignalR();
    }
}

我的windows客户端

代码语言:javascript
复制
public class Client
{
    private readonly string _platform;
    private readonly HubConnection _connection;
    private readonly IHubProxy _proxy;

    public event EventHandler<string> OnMessageReceived;

    public Client(string platform)
    {
        _platform = platform;
        _connection = new HubConnection("http://localhost");
        _proxy = _connection.CreateHubProxy("Chat");

    }

    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));
        });

        await Send("Connected");
    }

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

在我的MainWindow.xaml.cs

代码语言:javascript
复制
_client = new Client("Windows");

当我在部署Connect之后调用Hub时,它会抛出一个异常,其响应为

{StatusCode: 404, ReasonPhrase: '', Version: 0.0, Content: System.Net.Http.StreamContent, Headers: { Content-Length: 0 }}

我是不是漏掉了什么?我还检查了参考文献如何解决问题,但我似乎对他们的指导原则很满意。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-23 05:16:17

Windows 8模拟器是一台虚拟机。这意味着"localhost“引用的是VM/phone,而不是运行IIS/IISExpress的主机。

您可以使用主机名或IP地址连接到主机。

如果您决定坚持使用IIS Express,则需要配置Windows防火墙,以便在IIS Express运行的任何端口上接受入站请求。

关于如何从Windows 8模拟器连接到本地web服务的指南侧重于WCF,但同样适用于SignalR。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21949273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档