Exemple #1
0
        protected sealed override void ReciveMessage(Message message)
        {
            if (message.IsMessage((int)SOAMessageType.DoSOATransferRequest))
            {
                SOATransferRequest request = null;
                try
                {
                    var responseMsg = new Message((int)SOAMessageType.DoSOATransferResponse);
                    responseMsg.MessageHeader.TransactionID = message.MessageHeader.TransactionID;
                    SOATransferResponse responseBody = new SOATransferResponse();
                    request = message.GetMessageBody <SOATransferRequest>();
                    responseBody.ClientTransactionID = request.ClientTransactionID;
                    responseBody.ClientId            = request.ClientId;

                    if (SocketApplicationEnvironment.TraceMessage)
                    {
                        LogHelper.Instance.Debug(string.Format("接收服务请求,请求号:{0}", request.ClientTransactionID));
                    }

                    try
                    {
                        var result = DoResponse(request.FundId, request.Param, request.ClientId);
                        responseBody.Result    = LJC.FrameWork.EntityBuf.EntityBufCore.Serialize(result);
                        responseBody.IsSuccess = true;

                        if (SocketApplicationEnvironment.TraceMessage)
                        {
                            LogHelper.Instance.Debug(string.Format("处理请求:请求号:{0},客户端请求号:{1},服务号:{2},功能号:{3},结果:{4},序列化结果:{5}",
                                                                   responseMsg.MessageHeader.TransactionID, request.ClientTransactionID, ServiceNo, request.FundId, Comm.JsonUtil <object> .Serialize(result), Convert.ToBase64String(responseBody.Result)));
                        }
                    }
                    catch (Exception ex)
                    {
                        responseBody.IsSuccess = false;
                        responseBody.ErrMsg    = ex.Message;

                        LogHelper.Instance.Error(string.Format("服务转发出错,请求号:{0},服务号:{1},功能号:{2}",
                                                               request.ClientTransactionID, ServiceNo, request.FundId), ex);
                    }

                    responseMsg.SetMessageBody(responseBody);

                    this.SendMessage(responseMsg);

                    return;
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.Error(string.Format("服务转发出错,请求号:{0},服务号:{1},功能号:{2}",
                                                           request == null ? "0" : request.ClientTransactionID,
                                                           ServiceNo, request == null ? 0 : request.FundId), ex);

                    return;
                }
            }

            base.ReciveMessage(message);
        }
Exemple #2
0
        internal void DoTransferResponse(SOATransferResponse response)
        {
            try
            {
                Session session = null;

                ConatinerLock.EnterReadLock();
                ClientSessionList.TryGetValue(response.ClientTransactionID, out session);
                ConatinerLock.ExitReadLock();

                if (session != null)
                {
                    ConatinerLock.EnterWriteLock();
                    ClientSessionList.Remove(response.ClientTransactionID);
                    ConatinerLock.ExitWriteLock();

                    SOAResponse resp   = new SOAResponse();
                    Message     msgRet = new Message((int)SOAMessageType.DoSOAResponse);
                    msgRet.MessageHeader.TransactionID = response.ClientTransactionID;
                    resp.IsSuccess = response.IsSuccess;
                    resp.ErrMsg    = response.ErrMsg;
                    resp.Result    = response.Result;

                    msgRet.SetMessageBody(resp);
                    session.SendMessage(msgRet);

                    var toulp = (Tuple <int, int>)session.Tag;

                    if (SocketApplicationEnvironment.TraceMessage)
                    {
                        LogHelper.Instance.Debug(string.Format("SOA响应耗时,请求序列号:{0},服务号:{1},功能号:{2},用时:{3},结果:{4}",
                                                               response.ClientTransactionID, toulp.Item1, toulp.Item2, DateTime.Now.Subtract(session.BusinessTimeStamp).TotalMilliseconds + "毫秒",
                                                               Convert.ToBase64String(response.Result)));
                    }
                }
                else
                {
                    Exception ex = new Exception(string.Format("DoTransferResponse(SOATransferResponse response)失败,请求序列号:{0}", response.ClientTransactionID));
                    ex.Data.Add("response.ClientId", response.ClientId);

                    LogHelper.Instance.Error("DoTransferResponse出错", ex);
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("请求序列号", response.ClientTransactionID);

                LogHelper.Instance.Error("DoTransferResponse出错", ex);
            }
        }