Wow! I think I have seen this but I never really thought about it!!
I have tried to look for the answer based on housefly behavior but i do not think I have come up with anything yet. The closest I have come across might be due to the fact that flies taste using their feet and palps and their inability to take it solid food. So, the house flies mouth parts are adapted to taking only liquid and semisolid food. When a fly lands on solid food, it vomits saliva on the food and mixes it in order to make the food semi sold to enable it take the food. This is pure guess work- I would think then that they appear to be rubbing their fore legs during the vomiting and mixing stage.
An alternative explanation may be that they do this to clean their legs. House flies secrete sticky substances which help them walk upside down. So cleaning to allow them to taste whatever surface they have landed on? Maybe, just maybe.
Please tell me when you have an answer to this!