示例#1
0
 public void ReConnect(JMSClient tran)
 {
     ReConnectCount++;
     NetClient = NetClientPool.CreateClient(tran.ProxyAddress, this.InvokingInfo.ServiceLocation.Host, this.InvokingInfo.ServiceLocation.Port, tran.ServiceClientCertificate);
 }
示例#2
0
        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;
            }
        }
示例#3
0
 public Task <T> InvokeAsync <T>(string method, JMSClient tran, params object[] parameter)
 {
     return(Task.Run <T>(() => Invoke <T>(method, tran, parameter)));
 }
示例#4
0
 public Invoker(JMSClient ServiceTransaction, string serviceName)
 {
     this.ServiceTransaction = ServiceTransaction;
     _serviceName            = serviceName;
 }
示例#5
0
 public T Invoke <T>(string method, JMSClient tran, params object[] parameters)
 {
     return(this.Invoke <T>(method, tran, tran.GetCommandHeader(), parameters));
 }
示例#6
0
        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)));
        }
示例#7
0
 public Invoker(JMSClient ServiceTransaction, string serviceName, string arg = null)
 {
     this.ServiceTransaction = ServiceTransaction;
     _serviceName            = serviceName;
     _arg = arg;
 }