I have seen a wedding onboard on a sea day, on Princess. I don't know if the captain was performing the ceremony, but some ship's officer was. As we didn't know anyone in the wedding party, I didn't get any details. I believe Princess is one of very few - perhaps the only - major cruise lines that allow this.
One problem with marrying in one of the ports of call is that anything can happen - weather, mechanical problems, medical emergencies, etc. - that could cause the ship to skip that port. No port - no wedding. For that reason, doing it like Nancy described probably works best.