We have developed a technique for the in situ three-dimensional (3D) immobilization of primary rat hepatocytes within a localized matrix in a microfluidic channel that provides a 3D microenvironment incorporating both a configurable 3D matrix and fluid perfusion. This is based on the laminar flow complex coacervation of a pair of oppositely charged polyelectrolytes, i.e., methylated collagen and a terpolymer of HEMA-MMA-MAA. 3D collagen matrices were formed with minimal gelation times (<8 min), were able to entrap cells under aqueous noncytotoxic conditions, and permitted culture media to be perfused in the microchannel by virtue of the spatial confinement of the 3D matrix on one side of the channel. The architecture and stability of the collagen matrix could be configured by the use of different material combinations and changes in the polyelectrolyte flow rates and retention time. Primary rat hepatocytes cultured for 24 h in the 3D matrix within the microchannel showed comparable or enhanced cytochrome P450 7-ethoxyresorufin-O-deethylation activity with static controls. The configurable 3D microenvironment in the microfluidic channel may be a potential 3D culture model of primary hepatocytes for drug testing applications.