コード例 #1
0
        private static void ResponseCallback(IAsyncResult asyncResult)
        {
            RpcHttpClientTransaction trans  = (RpcHttpClientTransaction)asyncResult.AsyncState;
            RpcResponseHeader        header = null;

            try {
                var response = trans._webRequest.EndGetResponse(asyncResult);
                trans._webResponse = response;

                string warn = response.Headers.Get("Warning");

                if (!string.IsNullOrEmpty(warn))
                {
                    RpcErrorCode errCode = (RpcErrorCode)Enum.Parse(typeof(RpcErrorCode), warn);
                    if (errCode != RpcErrorCode.OK)
                    {
                        Exception ex = null;
                        if (response.ContentLength > 0)
                        {
                            Stream stream = response.GetResponseStream();
                            ex = BinarySerializer.Deserialize <Exception>(stream);
                        }
                        header = RpcResponseHeader.CreateError(errCode, ex);
                    }
                    else
                    {
                        SystemLog.Error(LogEventID.RpcFailed, "Unexcepted Message");
                        header = RpcResponseHeader.CreateError(RpcErrorCode.Unknown, null);
                    }
                }
                else
                {
                    bool hasBody = (response.Headers["Null"] != "true");
                    header = RpcResponseHeader.CreateSuccess(hasBody);
                }
            } catch (WebException ex) {
                if (ex.Status == WebExceptionStatus.Timeout)
                {
                    header = RpcResponseHeader.CreateError(RpcErrorCode.TransactionTimeout, ex);
                }
                else
                {
                    header = RpcResponseHeader.CreateError(RpcErrorCode.SendFailed, ex);
                }
            } catch (Exception ex) {
                header = RpcResponseHeader.CreateError(RpcErrorCode.SendFailed, ex);
            }
            trans._callback(header);
            trans._waitHandle.Set();
        }
コード例 #2
0
        private static void TimeoutCallback(object state, bool setted)
        {
            RpcHttpClientTransaction trans = null;

            try {
                if (setted)                   // Timeout
                {
                    trans = (RpcHttpClientTransaction)state;
                    var resp = RpcResponseHeader.CreateError(RpcErrorCode.TransactionTimeout, null);
                    trans._callback(resp);
                }
            } catch (Exception ex) {
                SystemLog.Error(LogEventID.RpcFailed, ex, "TimeoutCallback");
            } finally {
                if (trans != null)
                {
                    trans.Dispose();
                }
            }
        }
コード例 #3
0
        private static void TimeoutCallback(object state, bool timedOut)
        {
            RpcHttpClientTransaction trans = null;

            try {
                trans = (RpcHttpClientTransaction)state;

                if (trans._registeredHandle != null)
                {
                    trans._registeredHandle.Unregister(null);
                }

                if (timedOut)                   // Timeout
                {
                    var response = RpcResponse.Create(RpcErrorCode.TransactionTimeout, null);
                    trans.OnCallback(response);
                }
            } catch (Exception ex) {
                SystemLog.Error(LogEventID.RpcFailed, ex, "TimeoutCallback");
            }
        }