'성함' and '성명' are synonyms, but '성함' is a kind of '성명''s 높임말(respect forms). You could use '성함' when you ask someone "May I have your name?". '성함이 어떻게 되시나요?'
I think '성명' is a more neutral word. Usually you can see '성명' when you fill in the form asking your information such as name, address and so on.