public string UploadFile(string sourceFilePath, string targetDirectory) { var fileName = Path.GetFileName(sourceFilePath); if (fileName == null) { throw new Exception(string.Format("The file '{0}' is not a valid file.", sourceFilePath)); } lock (_locker) { try { _requestDispatcher.SendRequest(new UploadRequest { FilePath = Path.Combine(targetDirectory, fileName) }); _requestDispatcher.SendFile(sourceFilePath); var response = _requestDispatcher.ReceiveResponse <UploadResponse>(); return(response.FilePath); } catch (RequestException ex) { throw new RemoteClientException(string.Format("An error occured during the upload of {0}.", Path.GetFileName(sourceFilePath)), ex); } } }