Protect your rights
I know my legal rights, so politely asking for a badge number/name should be a no brainer. Personally, I would have a digital recorder in my pocket to record the event and would sue the town in a second for violating my civil rights and making a false arrest; could use the financial award to update my boat! Of course, don't argue with the official and be polite, but get information such as name, the official's boat registration number, date, time, description of the official, etc. all on the recorder. Have several copies of the current state law aboard and politely offer the official a copy. Contact the local town hall/harbor master and speak someone in charge to review their understanding of the law and your circumstances. Report to federal and state officials those communities not following the law, and get their names and title also. Go ahead and arrest me! I look forward to winning the punitive damages that follow such matters. Having said all this, don't be a jerk and usually an arrest will not happen - you can do all this and still obey the official! Remember, knowledge is real power and it can be wielded respectfully and politely. Make sure you know the state laws! If arrested, do not speak until you get into court to address the matter, and if not satisfied with the outcome, file a lawsuit (some may not have the time, but I would make a point of it because I despise bullies). Do not argue or get angry - use your knowledge of state law to win, and the next time you get harassed in that community, give the official a copy of your judgement. Again, knowledge is power!