This happened regularly at one time with a cat who would come into kitchen, eat cat food and wee on the washing machine! I have a four-way lockable cat flap and locked it so that he could come in, but not get out. I also had saucepan of cold water standing by. Cat came in, couldn't get out, rumpus ensued. I went into kitchen, spoke nicely to it and opened the back door (saucepan in other hand). As soon as the cat was going through the door, I drenched him.
It was the height of summer, so I wasn't concerned about the consequences to him. I wouldn't recommend this action in cold weather.
It worked.
He realised that coming here wasn't such a good idea!