信号器在显影机中使用websocket工作正常,但在生产(aws)中websocket不工作。 Error : WebSocket connection to 'wss://c99.comp.com/signalr/connect?transport=webSockets&clientProtocol=2.1&connectionToken=&connectionData=%5B%7B%22name%22%3A%22iestatushub%22%7D%5D&tid=4' failed: Error during WebSocket handshake: Unexpected response code: 400
之后,服务器上的信号器发送事件,而不是生产机器上的websocket。
应用程序位于asp.NETMVC3中,部署在带有redis的aws上,一次运行大约5个示例。
服务器上也启用了websocket,ssl就在那里。同时使用<httpruntime targetframework=“4.6”更新配置,但仍然无法工作!
任何帮助都将不胜感激。
客户:
$.connection.hub.logging = true;
function startIEStatusHub() {
if (ieStatusHubStarted == false) {
ieStatusHubStarted = true;
$.connection.hub.start()
.done(function () {
group = $("#_changeAgency_Home").val();
})
.fail(function () {
if (this.console) {
console.log("failed to connect to the hub.");
}
});
console.log("IE Status hub start.");
}
}
服务器端:
public class IEStatusHub : Hub
{
public override Task OnConnected()
{
string name = Context.User.Identity.Name;
Groups.Add(Context.ConnectionId, name);
return base.OnConnected();
}...
public class OwinStartup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
Global.asax
using Owin;
using System;
using System.Configuration;
using System.IO;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.Hosting;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.SessionState;
namespace Comp99.PP
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
var errorAttribute = new Comp99ErrorAttribute();
errorAttribute.HandleException += (s, e) =>
{
AwsClaimLogger.LogError("Unhandled exception: System unstable", e.ExceptionObject as Exception);
};
filters.Add(errorAttribute);
}
public static void RegisterWebApi(HttpConfiguration configuration)
{
configuration.Routes.MapHttpRoute("API Default", "api/{controller}/{id}",
new { id = RouteParameter.Optional });
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"ContentRoute", // Route name
"content/{action}/{id}/{version}", // URL with parameters
new { controller = "Content", action = "Index", id = UrlParameter.Optional, version = UrlParameter.Optional } // Parameter defaults
);
}
private void RedisConfiguration(IAppBuilder app)
{
string redisIP = ConfigurationManager.AppSettings["RedisConnection"];
int redisProQAPort = 6379;
if (ConfigurationManager.AppSettings["RedisProQAPort"] != null)
int.TryParse(ConfigurationManager.AppSettings["RedisProQAPort"], out redisProQAPort);
if (!string.IsNullOrEmpty(redisIP))
{
string[] ipAddresses = redisIP.Split(',');
if (ipAddresses.Length > 3)
{
string ipAddress = ipAddresses[0];
string password = ipAddresses[3].Remove(0, 9); // remove the "password=" string
// Any connection or hub wire up and configuration should go here
GlobalHost.DependencyResolver.UseRedis(ipAddress, redisProQAPort, password, "ProQAClaimIntegrator");
app.MapSignalR();
}
}
}
protected void Application_Start()
{
// Set up for SQL Server optimized sequential GUIDs.
GuidGenerator.Method = GuidGenerator.GenerationMethod.SQLServer;
var builder = new ContainerBuilder();
builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerHttpRequest();
builder.RegisterType<MpBillingUnitOfWork>().As<IMpBillingUnitOfWork>().InstancePerHttpRequest();
builder.RegisterType<ClaimViewModel>().AsSelf();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.RegisterControllers(typeof(PatientController).Assembly);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
AwsClaimLogger.Initialize();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
PortableAreaRegistration.RegisterEmbeddedViewEngine();
RegisterWebApi(GlobalConfiguration.Configuration);
RegisterRoutes(RouteTable.Routes);
AppBuilder app = new AppBuilder();
RedisConfiguration(app);
string audience = "...";
string issuer = "...";
string loginUrl = "...";
string communityLoginUrl = "...";
string privateKeyPath = "...";
string privateKeyPassword = "...";
string certificatePath = "...";
string certificatePassword = "...";
SalesForceSSO.SalesForceSSO.Instance.LoadConfiguration(
audience,
issuer,
loginUrl,
communityLoginUrl,
certificatePath,
certificatePassword,
privateKeyPath,
privateKeyPassword);
}
protected void Application_PostAuthorizeRequest()
{
if (IsWebApiRequest())
{
HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
}
}
private bool IsWebApiRequest()
{
return HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith("~/api");
}
}
}
暂无答案!
目前还没有任何答案,快来回答吧!