private static string SendData(this ConnectorBase connector, MethodCallInfo callInfo) { //TryAgain: bool isIgnorePriority = false; try { TaskCompletionSource <MethodCallbackInfo> valueData = new TaskCompletionSource <MethodCallbackInfo>(); CancellationTokenSource ct = new CancellationTokenSource(); ct.Token.Register(() => valueData.TrySetCanceled(), useSynchronizationContext: false); bool added = WaitedMethodsForResponse.TryAdd(callInfo.Guid, valueData); object service = connector.Services.ContainsKey(callInfo.ServiceName) ? connector.Services[callInfo.ServiceName] : null; //#if (PORTABLE) MethodInfo method = service?.GetType().FindMethod(callInfo.MethodName); //#else // var method = service?.GetType().FindMethod(callInfo.MethodName, RuntimeTypeHelper.GetMethodTypes(service.GetType(), callInfo).ToArray()); //#endif // isIgnorePriority = method?.GetCustomAttributes <PriorityCallAttribute>().Count() > 0; connector.SendData(callInfo); MethodCallbackInfo result = valueData.Task.Result; if (result == null) { if (connector.IsDisposed) { throw new ObjectDisposedException("Provider"); } if (!connector.IsConnected) { throw new Exception("client disconnected"); } return(null); } if (result.IsException) { throw new Exception("server exception:" + ClientSerializationHelper.DeserializeObject <string>(result.Data)); } else if (result.IsAccessDenied && result.Data == null) { throw new Exception("server permission denied exception."); } return(result.Data); } catch (Exception ex) { if (connector.IsConnected && !connector.SendPingAndWaitToReceive()) { connector.Disconnect(); } throw ex; } finally { WaitedMethodsForResponse.Remove(callInfo.Guid); } }