Esempio n. 1
0
 private static WcfServiceClient GetWcfClient(RequestSettings setting)
 {
     WcfServiceClient wcfClient = WcfServiceClientManager.Current.Get(setting.GameId, setting.ServerId);
     if (wcfClient == null)
     {
         throw new KeyNotFoundException(string.Format("Not found setting for game:{0} server:{1}", setting.GameId, setting.ServerId));
     }
     return wcfClient;
 }
Esempio n. 2
0
        private static bool DoCall(RequestSettings setting, out byte[] buffer, bool isRoute = false)
        {
            buffer = new byte[0];
            WcfServiceClient wcfClient = GetWcfClient(setting);

            if (wcfClient.Connect())
            {
                if (isRoute)
                {
                    return wcfClient.TryCallRemote(setting.RouteName, setting.ParamString, setting.RemoteAddress, out buffer);
                }
                return wcfClient.TryRequest(setting.ParamString, setting.RemoteAddress, out buffer);

            }
            return false;
        }
Esempio n. 3
0
 /// <summary>
 /// 发送请求
 /// </summary>
 public static bool Request(RequestSettings setting, out byte[] buffer)
 {
     return DoCall(setting, out buffer);
 }
Esempio n. 4
0
 /// <summary>
 /// 
 /// </summary>
 public static void ResetChannel(RequestSettings setting)
 {
     GetWcfClient(setting).ResetChannel();
 }
Esempio n. 5
0
 /// <summary>
 /// 远端调用
 /// </summary>
 public static bool CallRemote(RequestSettings setting, out byte[] buffer)
 {
     return DoCall(setting, out buffer, true);
 }
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 public static void ResetChannel(RequestSettings setting)
 {
     GetWcfClient(setting).ResetChannel();
 }
Esempio n. 7
0
 /// <summary>
 /// 远端调用
 /// </summary>
 public static bool CallRemote(RequestSettings setting, out byte[] buffer)
 {
     return(DoCall(setting, out buffer, true));
 }
Esempio n. 8
0
 /// <summary>
 /// 发送请求
 /// </summary>
 public static bool Request(RequestSettings setting, out byte[] buffer)
 {
     return(DoCall(setting, out buffer));
 }
Esempio n. 9
0
        /// <summary>
        /// 
        /// </summary>
        public void Request()
        {
            ReadParam();
            RequestSettings settings = new RequestSettings(GameId, ServerId, "", ParamString);

            byte[] sendBuffer = new byte[0];
            RequestError error = RequestError.Success;
            try
            {
                ServiceRequest.Request(settings, out sendBuffer);
            }
            catch (CommunicationObjectFaultedException fault)
            {
                TraceLog.WriteError("The wcfclient request faulted:{0}", fault);
                error = RequestError.Closed;
                ServiceRequest.ResetChannel(settings);
            }
            catch (Exception ex)
            {
                if (ex.InnerException is SocketException)
                {
                    var sex = ex.InnerException as SocketException;
                    TraceLog.WriteError("The wcfclient request connect:{0}-{1}", sex.SocketErrorCode, sex);
                    if (sex.SocketErrorCode == SocketError.TimedOut)
                    {
                        error = RequestError.Timeout;
                    }
                    else
                    {
                        error = RequestError.UnableConnect;
                    }
                }
                else
                {
                    TraceLog.WriteError("The wcfclient request error:{0}", ex);
                    error = RequestError.Unknown;
                }
                ServiceRequest.ResetChannel(settings);
            }
            switch (error)
            {
                case RequestError.Success:
                    WriteBuffer(sendBuffer);
                    break;
                case RequestError.Closed:
                case RequestError.NotFindService:
                    WriteNotFindError();
                    break;
                case RequestError.UnableConnect:
                    WriteConnectionError();
                    break;
                case RequestError.Timeout:
                    WriteTimeoutError();
                    break;
                case RequestError.Unknown:
                    WriteUnknownError();
                    break;
                default:
                    throw new ArgumentOutOfRangeException("RequestError", error, "Not process RequestError enum.");
            }
        }