/// <summary> /// 注册所有公共方法 /// </summary> /// <param name="server"></param> /// <param name="obj"></param> public static void RegisterService <T>(this HproseService server, object obj) where T : class { if (!(obj is T)) { return; } foreach (MethodInfo declaredMethod in obj.GetType().GetTypeInfo().DeclaredMethods) { if (declaredMethod.IsPublic) { server.Add(declaredMethod, obj, declaredMethod.Name, HproseResultMode.Normal, false); } } }
/// <summary> /// 启动服务 /// </summary> /// <param name="protocol">网络协议</param> /// <param name="port">监听端口</param> /// <param name="notifierName">通知器名称</param> /// <returns>错误信息</returns> public string Start(string protocol, int port, string notifierName, WriteLogDelegate writeLog = null) { try { if (m_Service != null) { if (m_Service.IsStarted()) { return(string.Empty); } } else { //var notifierName = ConfigHelper.GetValue("Notifier"); var notifier = GetNotifier(notifierName); if (null == notifier) { throw new Exception("创建通知器实例失败"); } if (writeLog != null) { notifier.SetLogger(writeLog); } //var port = ConfigHelper.GetInt32("ListenPort"); //var protocol = ConfigHelper.GetValue("NetProtocol").LowerCase(); m_Service = GetServer(protocol, port); m_Service.Add("SendMessage", notifier); } m_Service.Start(); return(m_Service.IsStarted() ? string.Empty : "服务启动失败"); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// 注册所有公共方法 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="server"></param> /// <param name="implement"></param> public static void RegisterService <T>(this HproseService server, object implement) where T : class { var methods = typeof(T).GetMethods().Where(t => t.IsPublic).Select(t => t.Name).ToArray(); server.Add(methods, implement); }