/// <summary> /// Invokes the capability and returns the return value /// </summary> /// <param name="argument">The invocation argument</param> /// <returns>The return value</returns> public Either <IError, TReturn> Invoke(TArgument argument) { _socket.SendMultipartMessage(CreateRequest(argument)); var response = _socket.ReceiveMultipartMessage(); var messageType = (MessageType)response.Pop().ConvertToInt32(); switch (messageType) { case MessageType.CapabilityInvocationResult: return(new Right <IError, TReturn>( JsonConvert.DeserializeObject <TReturn>(_encryptor.Decrypt(response.Pop().ToByteArray())))); case MessageType.Error: var error = JsonConvert.DeserializeObject <ErrorCode>(response.Pop().ConvertToString()); return(new Left <IError, TReturn>(ErrorUtilities.GetErrorByErrorCode(error))); default: throw new ArgumentOutOfRangeException(); } }