async Task OnRequest(HttpContext context) { var request = context.Request; var response = context.Response; response.Headers.Add("Access-Control-Allow-Origin", "*"); var path = request.Path.Value; var arry = path.Split('/'); var service = arry[2]; var method = arry[3]; var token = request.Headers["token"]; var requestMsg = new RequestJsonMessage() { Service = service, Method = method, Token = token, }; if (request.ContentLength > 0) { var reader = new StreamReader(request.Body); var args = await reader.ReadToEndAsync(); requestMsg.Args = args.ToObject <List <object> >(); } //var instance = ServerCreater.Instance; var server = _serverCreater.GetServer(); var result = server.InvokeResult(requestMsg, type => { //获取注入的AbsService return(_serviceProvider.GetService(type)); }); await response.WriteAsync(result.ToJson()); }
static void Main(string[] args) { var server = new ServerCreater().CreateWebSocket(8015); server.CheckSign(); server.SetSessionManage(new SessionManage()); //server.Register<ITestService, TestService>(); server.RegisterAll(System.Reflection.Assembly.GetAssembly(typeof(TestService))); server.Start(); new CRL.Core.ThreadWork().Start("send", () => { var socket = server.GetServer() as CRL.WebSocket.WebSocketServer; socket.SendMessage("hubro", new socketMsg() { name = DateTime.Now.ToString() }, out string error); Console.WriteLine("send msg"); return(true); }, 10); Console.ReadLine(); }