在我的服务器端,我只有一个简单的MVC服务器端。
<?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>和
public class Chat : Hub
{
public void Send(string platform, string message)
{
Clients.All.messageReceived(platform, message);
}
}和
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}我的windows客户端
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里
_client = new Client("Windows");当我在部署Connect之后调用Hub时,它会抛出一个异常,其响应为
{StatusCode: 404, ReasonPhrase: '', Version: 0.0, Content: System.Net.Http.StreamContent, Headers: { Content-Length: 0 }}
我是不是漏掉了什么?我还检查了参考文献如何解决问题,但我似乎对他们的指导原则很满意。
发布于 2014-02-23 05:16:17
Windows 8模拟器是一台虚拟机。这意味着"localhost“引用的是VM/phone,而不是运行IIS/IISExpress的主机。
您可以使用主机名或IP地址连接到主机。
如果您决定坚持使用IIS Express,则需要配置Windows防火墙,以便在IIS Express运行的任何端口上接受入站请求。
关于如何从Windows 8模拟器连接到本地web服务的指南侧重于WCF,但同样适用于SignalR。
https://stackoverflow.com/questions/21949273
复制相似问题