private void HandleRemoteInvoke(CommandContextEx cmdContext) { CLRLogger.GetInstance().LogDevInfo("Handle remote invoke, sender is " + cmdContext.sSender); byte[] request = cmdContext.sSerializeObject; _currentRemoteInvoker.Value = cmdContext.sSender; BinaryFormatter formatter = new BinaryFormatter(); RemoteMethodInvokeArgument invokeArgs = null; using (MemoryStream inStream = new MemoryStream(request)) { invokeArgs = formatter.Deserialize(inStream) as RemoteMethodInvokeArgument; } if (invokeArgs == null) { throw new Exception("Invalid remote argument"); } object obj = NativeInvoke(invokeArgs.ObjectName, invokeArgs.Method, invokeArgs.Parameters); using (MemoryStream outStream = new MemoryStream()) { formatter.Serialize(outStream, obj); byte[] response = outStream.GetBuffer(); int errorCode = cmdContext.Reply(response); if (errorCode != 0) { throw new CommunicationException(errorCode, "fail to reply to " + cmdContext.sSender); } } }
public object RemoteInvoke(string receiver, string serviceObjectName, MethodBase method, params object[] parameters) { if (receiver == _communicationProxy.GetName()) { return(NativeInvoke(serviceObjectName, method, parameters)); } RemoteMethodInvokeArgument args = new RemoteMethodInvokeArgument(serviceObjectName, method, parameters); BinaryFormatter formatter = new BinaryFormatter(); using (MemoryStream outStream = new MemoryStream()) { CommandContext cmdContext = new CommandContext(); _communicationProxy.GetName(); formatter.Serialize(outStream, args); cmdContext.iCommandId = COMMUNICATION_ID; cmdContext.sReceiver = receiver; cmdContext.sSender = _communicationProxy.GetName(); cmdContext.sSerializeObject = outStream.GetBuffer(); cmdContext.iWaitTime = WAIT_TIME; ISyncResult result = _communicationProxy.SyncSendCommand(cmdContext); if (result.GetCallResult() != 0) { throw new CommunicationException(result.GetCallResult(), "fail to sync send command to " + receiver); } using (MemoryStream replyStream = new MemoryStream(result.GetSerializedObject())) { return(formatter.Deserialize(replyStream)); } } }//EndMethod