Do organisms use detergents to fight off viruses?
To answer your question, consider why soap is effective against bacteria and viruses.  The chemistry of detergents allows them to interrupt the lipid layer that surrounds cells and some viruses.  Viral envelopes, in particular, tend to be composed of host-derived phospholipids and proteins.  So, if an organism were to synthesize a detergent to fight off a pathogen, that detergent would pose a threat to the producing organism, as well.  



Edit - most air-breathing animals produce a pulmonary surfactant in their alveolar cells, though the purpose of these molecules is lung function and cell size regulation, not immunity.