public T Invoke <T>(string method, JMSClient tran, params object[] parameters) { return(this.Invoke <T>(method, tran, tran.GetCommandHeader(), parameters)); }
public T Invoke <T>(string method, JMSClient tran, params object[] parameters) { if (tran == null) { throw new ArgumentNullException("tran"); } this.InvokingInfo.MethodName = method; this.InvokingInfo.Parameters = parameters; var netclient = NetClientPool.CreateClient(tran.ProxyAddress, this.InvokingInfo.ServiceLocation.Host, this.InvokingInfo.ServiceLocation.Port, tran.ServiceClientCertificate); try { var cmd = new InvokeCommand() { Header = tran.GetCommandHeader(), Service = this.InvokingInfo.ServiceName, Method = method, Parameters = parameters.Length == 0 ? null : parameters.GetStringArrayParameters() }; netclient.WriteServiceData(cmd); var result = netclient.ReadServiceObject <InvokeResult <T> >(); if (result.Success == false) { throw new RemoteException(tran.TransactionId, result.Error); } NetClient = netclient; if (result.SupportTransaction) { tran.AddConnect(this); } else { NetClientPool.AddClientToPool(netclient); } return(result.Data); } catch (ConvertException ex) { InvokeResult <string> otherObj = null; try { otherObj = ex.Source.FromJson <InvokeResult <string> >(); } catch { } if (otherObj != null) { throw new ConvertException(otherObj.Data, $"无法将{otherObj.Data}实例化为{typeof(T).FullName}"); } throw ex; } catch (Exception) { netclient.Dispose(); throw; } }
public Task <T> InvokeAsync <T>(string method, JMSClient tran, params object[] parameter) { var headers = tran.GetCommandHeader(); return(Task.Run <T>(() => Invoke <T>(method, tran, headers, parameter))); }