EDIT (7 November 2012)
I'm glad to be able to announce that, as of today, the provisions of section 13(2) of the Copyright Act (RSC 1985 c. C-42) are repealed through Bill C-11, and moral rights in photographic work now vest in the photographer (and let's not forget portraitists in other media either) unless normal work-for-hire conditions exist, or an agreement to the contrary has been established.
It's about time, and my thanks to CAPIC and PPoC for keeping up the fight all these years.
That makes the rest of this answer of historical interest only.
The "agreement to the contrary" needs to be very explicit and carefully worded.
The default assumption in fields deemed to be graphic arts (traditionally, things like engraving and lithography, but under which photography also falls by law) is that the contribution of the graphic artist is of a purely technical nature. In other words, one is normally deemed to be nothing more than a "camera operator", someone who merely records what is -- like an engraver or lithographer who copies an illustration for use in print, it is assumed that you are merely a walking set of technical skills with a tool kit.
The reason it needs to be carefully worded is because it is very difficult, under Canadian law, for a person to relinquish their natural copyright in a work. It is impossible, for instance, to release any work into the public domain voluntarily -- the best you can do is to grant license to everyone for every purpose, gratis, and without requirement for attribution, but that license is revocable at will. Similarly, assignment of all rights in a work (which the customer holds naturally under commission) is difficult to make in an irrevocable manner, so the language around the agreement needs to be clear regarding both the intent as to who will hold copyright and as to who has creative control in the production of the image.
If it's not clear that you, as the photographer, are acting in the capacity of a creative artist, then even an explicit agreement that you will hold copyright in the resulting work may not, in fact, be legally binding. The intent of the law surrounding the alienation of natural copyright is good; the fact that photography is deemed in the Act to be little more than a technical process in the reproductive arts is not so good.