The \caption macro only works in float environments like table or figure (unless you want a non-floating description for a figure, then you can use the \captionof macro provided by the caption package or the KOMA-Script classes.
The \xymatrix is not horizontally centered by default, you can use either LaTeX’s \[ … \] macros (which adds vertical space that is removed with \tightdisplaymath) or—not recommended—a manual centering with the \centerline macro or a pair of \hspace{\fill}.
Do not use [h] or [h!] in your document. It is only used here to show the floats on one page. If you want fixed positions in your running text use \captionof or simply a numbered math environment.
Code
\documentclass{book}
\usepackage[a4paper,margin=.45in]{geometry}
\usepackage[all]{xy}
\makeatletter
\newcommand*{\tightdisplaymath}{\abovedisplayskip\z@\belowdisplayskip\z@}
\makeatother
\begin{document}
\hrulefill
\begin{figure}[h]
\[ \xymatrix{
A \ar[r]\ar[d] & B\ar[d]\\
C \ar[r] & D
} \]
\caption{Rectangular diagram}\label{Fig1a}
\end{figure}
\hrulefill
\begin{figure}[h] \tightdisplaymath
\[ \xymatrix{
A \ar[r]\ar[d] & B\ar[d]\\
C \ar[r] & D
} \]
\caption{Rectangular diagram}\label{Fig1b}
\end{figure}
\hrulefill
\begin{figure}[h] \centerline{%
\xymatrix{
A \ar[r]\ar[d] & B\ar[d]\\
C \ar[r] & D
}}
\caption{Rectangular diagram}\label{Fig2}
\end{figure}
\hrulefill
\begin{figure}[h!]
\hspace{\fill}%
\xymatrix{
A \ar[r]\ar[d] & B\ar[d]\\
C \ar[r] & D
}%
\hspace{\fill}
\caption{Rectangular diagram}\label{Fig3}
\end{figure}
\hrulefill
\hrulefill
Figure \ref{Fig1a} and \ref{Fig1b} are commutative diagrams.
Figure \ref{Fig2} is the same commutative diagram.
Figure \ref{Fig3} is also the same commutative diagram.
\end{document}
Output

\protectthings like\captionand\labelif they don't seem to work in a situation. – Steven B. Segletes May 23 '13 at 12:27figureortableto use the\captionmacro. If you don't want a float, take a look at the\captionofmacro from thecaptionpackage. Besides that, the package is simply calledxy:\usepackage[all]{xy}works. – Qrrbrbirlbel May 23 '13 at 13:15\begin{figure} ... \end{figure}. See http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions. Also, don't use$$for display math, use\[ ... \](see Why is [ … ] preferable to $$ … $$?) – Jake May 23 '13 at 13:16xymatrix– daleif May 23 '13 at 13:17xymatrixis environment defined in xy-pic package which is loaded by\usepackage[all]{xy}in preamble – texenthusiast May 23 '13 at 13:25green tickto encourage/thank people. All the best. – texenthusiast May 23 '13 at 13:37