【发布时间】:2016-02-02 23:05:45
【问题描述】:
我有一个带有辅助角色的 Azure 云服务,它在启动时启动一个使用 SignalR 的 OWIN Web 应用程序。
另外,我有一个控制台项目,它使用 SignalR 客户端库连接到此辅助角色并侦听事件。
当我使用 Azure 模拟器在本地运行客户端和服务时,一切正常。
当我发布云服务并将控制台应用程序指向它并尝试连接时,我在 SignalR 跟踪日志中得到以下信息:
WS Connecting to: ws://myapp.cloudapp.net/signalr/connect?clientProtocol=1.4&transport=webSockets&connectionData=[{"Name":"MessageBusHub"}]&connectionToken=...
OnError(System.Net.WebSockets.WebSocketException (0x80004005): An internal WebSocket error occurred. Please see the innerException, if present, for more details. ---> System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
然后它会继续使用服务器发送的事件和长轮询再次尝试,每次都会出现相同的错误。
我在我的云服务配置中使用以下端点:
<Endpoints>
<InputEndpoint name="SignalREndpoint" protocol="http" port="80" localPort="80" />
</Endpoints>
以下是我创建 OWIN Web 应用程序的方法:
var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["SignalREndpoint"];
string webAppUrl = $"{endpoint.Protocol}://{endpoint.IPEndpoint}";
_webApp = WebApp.Start<Startup>(webAppUrl);
最后,我是这样配置 SignalR 的:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.UseServerAuthentication();
GlobalHost.DependencyResolver.UseServiceBus(CloudConfigurationManager.GetSetting("ServiceBusConnectionString"), "SignalRMessageBus");
app.MapSignalR(new HubConfiguration()
{
EnableDetailedErrors = true,
});
}
}
在客户端项目中,我只是使用 HubConnection 进行连接,使用以下 URL 进行本地测试,http://localhost:80,并使用以下 URL 连接到云实例,http://myapp.cloudapp.net
我不确定实际的 Azure 实例和我的本地模拟器之间有什么不同导致它无法在云中运行。
有趣的是,如果我使用浏览器连接到 URL http://myapp.cloudapp.net/signalr/hubs,它会工作并返回 JS 代理文件。
【问题讨论】:
标签: c# azure signalr owin azure-worker-roles