You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

68 lines
2.5 KiB

  1. using Microsoft.AspNet.SignalR;
  2. using Owin;
  3. using Microsoft.Owin.Cors;
  4. using Microsoft.Owin.Hosting;
  5. using System;
  6. using System.Reflection;
  7. using Learun.Util;
  8. namespace Learun.Application.IMServer
  9. {
  10. public class Startup
  11. {
  12. /// <summary>
  13. /// 开启服务
  14. /// </summary>
  15. public static void Start()
  16. {
  17. string SignalRURI = Config.GetValue("IMUrl");
  18. try
  19. {
  20. try
  21. {
  22. using (WebApp.Start(SignalRURI, builder =>
  23. {
  24. builder.Map("/signalr", map =>
  25. {
  26. // Setup the cors middleware to run before SignalR.
  27. // By default this will allow all origins. You can
  28. // configure the set of origins and/or http verbs by
  29. // providing a cors options with a different policy.
  30. map.UseCors(CorsOptions.AllowAll);
  31. var hubConfiguration = new HubConfiguration
  32. {
  33. // You can enable JSONP by uncommenting line below.
  34. // JSONP requests are insecure but some older browsers (and some
  35. // versions of IE) require JSONP to work cross domain
  36. EnableJSONP = true
  37. };
  38. // Run the SignalR pipeline. We're not using MapSignalR
  39. // since this branch is already runs under the "/signalr"
  40. // path.
  41. map.RunSignalR(hubConfiguration);
  42. });
  43. builder.MapSignalR();
  44. }))
  45. {
  46. Console.WriteLine("服务开启成功,运行在{0}", SignalRURI);
  47. Console.ReadLine();
  48. }
  49. }
  50. catch (TargetInvocationException exception)
  51. {
  52. Console.WriteLine("服务开启失败. 已经有一个服务运行在{0}. 异常信息:{1}", SignalRURI, exception.ToString());
  53. Console.ReadLine();
  54. }
  55. }
  56. catch (Exception ex)
  57. {
  58. Console.WriteLine("服务开启异常:{0}", ex.ToString());
  59. Console.ReadLine();
  60. }
  61. }
  62. }
  63. }