Trade ports give you an increase in credit income. Every trade port in your empire (unless the target planet has a bonus, like +10% trade income) gives the same amount of benefit. However, if a trade ship is destroyed, its home port suffers reduced income for a short duration. The amount of money each trade port gives you is based on the "longest chain" of trade ports in your empire.
Refineries simply increase the amount of resources produced by all resource asteroids in their area of effect. For Advent, this is all resource asteroids in their own gravity well. For TEC and Vasari, this is every asteroid in the gravity well you placed the refinery, and every asteroid in adjacent gravity wells as well. Each asteroid can be affected by only three refineries; any more and they stop giving benefit. However, the Advent resource focus doesn't have this limit, and you can keep adding more beyond that point. However, it is still the worst refinery by far.
Most of the time, trade ports are always better than refineries. However, sometimes placing a trade port will interfere with your longest trade route (if it provides a shortcut across your empire, for instance). Other times it's literally teeming with resource asteroids. In these cases, the refinery is a good investment. Typically players invest in lots of trade ports early on to build a high credit income, then add refineries later on.