public object Call(string methodName, object[] parameters) { var payload = Payload.Create(parameters, o => _eloquentClient.TryGetObjectId(o, out var id) ? id : null); var requestMessage = payload.CreateRequestMessage(_serializer, _clientHostAddress, _objectId, methodName); var result = _outputChannel.SendAndReceive(requestMessage); switch (result) { case ErrorMessage errorMessage: throw errorMessage.ToException(); case ExceptionMessage exceptionMessage: throw exceptionMessage.Exception; case ResponseMessage responseMessage: if (responseMessage.Selector[0]) { var objectType = _contractDescription.GetOperationDescription(methodName, parameters).Method.ReturnType; return(_eloquentClient.Connect(objectType, responseMessage.ObjectIds[0])); } else { return(_serializer.Deserialize(responseMessage.SerializedParameters).Single()); } default: throw new IOException($"Unexpected session message type: {result.MessageType}"); } }