/// <summary> /// 处理返回消息 /// </summary> /// <param name="msgData">返回消息</param> private object DealRepMessage(byte[] msgData) { TSerializer serializerResp = new TBinarySerializer(); serializerResp.FromBytes(msgData); TMessage respMsg = serializerResp.ReadMessageBegin(); if (respMsg.Type == TMessageType.Exception) { this.RaiseDealMessageExceptionEvent(TApplicationException.Read(serializerResp)); serializerResp.ReadMessageEnd(); serializerResp.Flush(); return(null);; } if (respMsg.Type != TMessageType.RpcReply) { this.RaiseDealMessageExceptionEvent(new ApplicationException("非法的返回类型:" + respMsg.Type.ToString())); serializerResp.ReadMessageEnd(); serializerResp.Flush(); return(null); } string[] temp = respMsg.Name.Split('_'); DynMethodInstance dynMethodInstance = new DynMethodInstance(temp[0], temp[1]); try { dynMethodInstance.Result = DynSerialize.ReadResult(serializerResp, dynMethodInstance); } catch (Exception ex) { this.RaiseDealMessageExceptionEvent(ex); serializerResp.ReadMessageEnd(); serializerResp.Flush(); } // 消息结束 serializerResp.ReadMessageEnd(); serializerResp.Flush(); return(dynMethodInstance.Result); }
/// <summary> /// 处理返回消息 /// </summary> /// <param name="msgData">返回消息</param> private object DealRepMessage(byte[] msgData, string msgID, out bool isReceive) { //初始化序列化容器 TSerializer serializerResp = new TBinarySerializer(); //将数据读入序列化容器 serializerResp.FromBytes(msgData); //从序列化容器中读取消息 TMessage respMsg = serializerResp.ReadMessageBegin(); //如果消息的id不对返回空值 if (msgID != respMsg.MsgID) { //空方法 serializerResp.ReadMessageEnd(); serializerResp.Flush(); isReceive = false; return(null); } //如果是异常消息 if (respMsg.Type == TMessageType.Exception) { TApplicationException appException = TApplicationException.Read(serializerResp); this.RaiseDealMessageExceptionEvent(appException); serializerResp.ReadMessageEnd(); serializerResp.Flush(); throw appException; } //如果消息是远程调用回应 if (respMsg.Type != TMessageType.RpcReply) { this.RaiseDealMessageExceptionEvent(new ApplicationException("非法的返回类型:" + respMsg.Type.ToString())); serializerResp.ReadMessageEnd(); serializerResp.Flush(); isReceive = true; return(null); } //构造方法的实例 string[] temp = respMsg.Name.Split('_'); DynMethodInstance dynMethodInstance = new DynMethodInstance(temp[0], temp[1]); try { dynMethodInstance.Result = DynSerialize.ReadResult(serializerResp, dynMethodInstance); } catch (Exception ex) { this.RaiseDealMessageExceptionEvent(ex); serializerResp.ReadMessageEnd(); serializerResp.Flush(); } // 消息结束 serializerResp.ReadMessageEnd(); serializerResp.Flush(); isReceive = true; return(dynMethodInstance.Result); }