/// <summary> /// 消息回调 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void reqService_OnCallback(object sender, ServiceMessageEventArgs args) { if (args.Result is ResponseMessage) { var resMsg = args.Result as ResponseMessage; base.QueueMessage(resMsg); } else if (args.Result is CallbackMessage) { var callbackMsg = args.Result as CallbackMessage; if (callback != null) { var callbackType = callback.GetType(); //获取接口的类型 var interfaces = callbackType.GetInterfaces(); if (interfaces.Length > 0) { //判断类型是否相同 if (interfaces.Any(type => type.FullName == callbackMsg.ServiceName)) { var method = CoreHelper.GetMethodFromType(callbackType, callbackMsg.MethodName); //执行委托 DynamicCalls.GetMethodInvoker(method).Invoke(callback, callbackMsg.Parameters); } } } } }
void client_MessageReceived(object sender, MessageEventArgs e) { var message = new ServiceMessageEventArgs { Client = client, Request = request }; //不是指定消息不处理 if (e.Message is ScsCallbackMessage) { //消息类型转换 var data = e.Message as ScsCallbackMessage; message.Result = data.MessageValue; } else if (e.Message is ScsResultMessage) { //消息类型转换 var data = e.Message as ScsResultMessage; message.Result = data.MessageValue; } //把数据发送到客户端 if (OnCallback != null) OnCallback(this, message); }
void reqService_OnCallback(object sender, ServiceMessageEventArgs args) { if (args.Result is ResponseMessage) { var resMsg = args.Result as ResponseMessage; QueueMessage(resMsg); } }