This isn’t an uncommon situation, and the answer is that the appraisal is a required part of the loan process, and the cost is the applicant’s responsibility, but just because an appraisal is done, it does not guarantee loan approval. Lenders now typically get a credit card deposit prior to ordering an appraisal, and once the appraiser has completed his work, the borrower and lender are responsible for paying for the appraisal, regardless of loan status. In answer to your question, you can ask, but being denied for a loan does not typically mean you are entitled to a refund on the appraisal cost.
No, you won’t get a refund from the appraiser or the lender once the appraisal is performed. However, you may be able to persuade the new lender to accept the appraisal that was done by the prior lender’s appraiser.
You can ask if the appraisal can be transferred, but more often that not lenders want to use appraisals they order themselves to assure that there was no undue influence involved in the appraisal.