Beispiel #1
0
        public bool Init(RegisterServiceLocation registerServiceLocation)
        {
            //获取服务地址
            var netclient = NetClientPool.CreateClient(this.ServiceTransaction.ProxyAddress, this.ServiceTransaction.GatewayAddress, this.ServiceTransaction.GatewayClientCertificate);

            netclient.ReadTimeout = this.ServiceTransaction.Timeout;
            try
            {
                netclient.WriteServiceData(new GatewayCommand()
                {
                    Type    = CommandType.GetServiceProvider,
                    Header  = ServiceTransaction.GetCommandHeader(),
                    Content = new GetServiceProviderRequest
                    {
                        ServiceName = _serviceName,
                        Arg         = _arg
                    }.ToJsonString()
                });
                var serviceLocation = netclient.ReadServiceObject <RegisterServiceLocation>();
                if (registerServiceLocation != null)
                {
                    serviceLocation.Host           = registerServiceLocation.Host;
                    serviceLocation.Port           = registerServiceLocation.Port;
                    serviceLocation.ServiceAddress = registerServiceLocation.ServiceAddress;
                }

                if (serviceLocation.Host == "not master")
                {
                    throw new MissMasterGatewayException("");
                }

                if (string.IsNullOrEmpty(ServiceTransaction.TransactionId))
                {
                    ServiceTransaction.TransactionId = serviceLocation.TransactionId;
                }

                if (serviceLocation.Port == 0)
                {
                    return(false);
                }
                _serviceLocation = serviceLocation;

                NetClientPool.AddClientToPool(netclient);
            }
            catch (SocketException ex)
            {
                netclient.Dispose();
                throw new MissMasterGatewayException(ex.Message);
            }
            catch (Exception)
            {
                netclient.Dispose();
                throw;
            }


            return(true);
        }
 void outputResult(NetClient netclient, GatewayCommand cmd, RegisterServiceLocation location)
 {
     if (cmd.IsHttp)
     {
         if (location.Host.Length == 0)
         {
             var contentBytes = Encoding.UTF8.GetBytes("{}");
             netclient.OutputHttpContent(contentBytes);
         }
         else
         {
             var contentBytes = Encoding.UTF8.GetBytes(location.ToJsonString());
             netclient.OutputHttpContent(contentBytes);
         }
     }
     else
     {
         netclient.WriteServiceData(location);
     }
 }
Beispiel #3
0
 public InvokeConnect(string serviceName, RegisterServiceLocation location)
 {
     this.InvokingInfo                 = new InvokingInformation();
     this.InvokingInfo.ServiceName     = serviceName;
     this.InvokingInfo.ServiceLocation = location;
 }