I am trying to access SignalR hosted in Azure mobile service from a Apache Cordova app, while starting the hub connection I get an error 403 Forbidden: JSONP is disabled at the negotiating request with web socket protocol. I tried adding EnableJsonP as below but it still gives the same issue, Is there any other way to enablejsonp for a azure hosted mobile service.
public static class WebApiConfig
{
public static void Register()
{
SignalRExtensionConfig.Initialize();
// Use this class to set configuration options for your mobile service
ConfigOptions options = new ConfigOptions();
options.SetRealtimeAuthorization(AuthorizationLevel.Anonymous);
//// Use this class to set WebAPI configuration options
var configBuilder = new ConfigBuilder(options, (httpconfig, ioc) =>
{
ioc.RegisterInstance(new CORSSignalROwinAppBuilderExtension(httpconfig)).As<IOwinAppBuilderExtension>();
});
HttpConfiguration config = ServiceConfig.Initialize(configBuilder);
config.Formatters.JsonFormatter.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include;
config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include;
Database.SetInitializer(new snackappmobileInitializer());
}
}
internal class CORSSignalROwinAppBuilderExtension : OwinAppBuilderExtension
{
private HttpConfiguration httpconfig;
protected override void ConfigureSignalR(IAppBuilder appBuilder)
{
appBuilder.Map("/signalr", map =>
{
var hubConfiguration = new HubConfiguration
{
EnableJSONP = true
};
map.RunSignalR(hubConfiguration);
});
base.ConfigureSignalR(appBuilder);
}
public CORSSignalROwinAppBuilderExtension(HttpConfiguration httpconfig) : base(httpconfig)
{
this.httpconfig = httpconfig;
}
}
There are two different ways to work with Azure Mobile - App Service and Mobile Services. If you are in the Classic Portal to configure things (https://manage.windowsazure.com) then you are using Mobile Services. If not, you are in App Service. Based on the question, my belief is that you are using Mobile Services, so I recommend an upgrade if you are still developing - use App Service instead!
App Service does not do anything special with SignalR, so all the "normal" SignalR stuff should just work. You can check out this link for doing SignalR the "normal" way: signalR CORS - IE client gets 403 'Forbidden: JSONP is disabled'
Mobile Services is different. We do wire up a bunch of things for SignalR. It looks like you are calling Mobile Services to initialize SignalR and then trying to initialize it yourself. I'm not sure what would happen there but something likely won't get wired up properly.
Again, if you are using Mobile Services, then I recommend upgrading to Azure App Service Mobile Apps. There are SDK version changes, but Mobile Apps doesn't do anything with SignalR, so things will work the normal way for you.