/// <summary> /// 响应委托 /// </summary> /// <param name="proxy"></param> /// <param name="method"></param> /// <param name="parameters"></param> /// <returns></returns> public object Invoke(object proxy, System.Reflection.MethodInfo method, object[] parameters) { object returnValue = null; var collection = IoCHelper.CreateParameters(method, parameters); string cacheKey = IoCHelper.GetCacheKey(serviceType, method, collection); var cacheValue = cache.GetCache <CacheObject>(cacheKey); //缓存无值 if (cacheValue == null) { //调用方法 var resMsg = InvokeMethod(method, collection); if (resMsg != null) { returnValue = resMsg.Value; //处理参数 IoCHelper.SetRefParameterValues(method, resMsg.Parameters, parameters); //如果需要缓存,则存入本地缓存 if (returnValue != null && cacheTimes.ContainsKey(method.ToString())) { int cacheTime = cacheTimes[method.ToString()]; cacheValue = new CacheObject { Value = resMsg.Value, Parameters = resMsg.Parameters }; cache.InsertCache(cacheKey, cacheValue, cacheTime); } } } else { //处理返回值 returnValue = cacheValue.Value; //处理参数 IoCHelper.SetRefParameterValues(method, cacheValue.Parameters, parameters); } //返回结果 return(returnValue); }
/// <summary> /// Gets the service. /// </summary> /// <param name="reqMsg"></param> /// <returns></returns> private IService ParseService(RequestMessage reqMsg) { IService service = null; string serviceKey = "Service_" + reqMsg.ServiceName; if (status.Container.Kernel.HasComponent(serviceKey)) { service = status.Container.Resolve <IService>(serviceKey); } if (service == null) { string body = string.Format("The server【{1}({2})】not find matching service ({0})." , reqMsg.ServiceName, DnsHelper.GetHostName(), DnsHelper.GetIPAddress()); //获取异常 throw IoCHelper.GetException(OperationContext.Current, reqMsg, body); } return(service); }