My understanding is that ものだ is used to assert things which are mostly known to everyone.
'When invited to somebody's home it's customary to bring presents'.
On the other hand, ことだ is used to advice.
I can understand that B gives an advise to A, however B is not really saying anything that A couldn't already know. Moreover, when talking about what to do when going to somebody's home, "bring presents" is not necessarily something that everybody is aware of - could be that some cultures are used to bringing money.
So it seems to be that, in the examples above, ものだ and ことだ are can be freely exchanged. Note, that the examples are from my textbook so i guess they can't be exchanged.