The same thing happened to myself and Mrs FD last autumn when we applied for a mortgage (Mrs FD has a slightly dodgy credit history from 5 years ago, and beleive me we have researched this to the hilt. We had an agreement in principal 2 weeks before due to sign, and then out of the blue we got a letter saying our application had been declined.
Apperently the agreement in principals is meaningless and its only when the underwritting is checked (which is done much much more rigorously than in the past) that a decision is actually made whether to give you a mortgage.
Our IFA was invaluable as he found an alternative mortgage. Basically the house is now solely in my name has we didnt want to risk my wife having another credit scoring. Our IFA said he had gone for a Fast Track mortgage. I didn't even have to provide my pay slips etc.
The ridiculous thing is that I now have the mortgage soley in my name, where my salary only just covers the monthly payment !
Whatever you do, DO NOT just go on the high street and apply for another mortgage, your credit score will now show that a recent application was turned down, limiting further your chance of getting a mortgage. I assume that your application was turned down as your wife is not in full time employment, and a letter confirming that they may take her on full time is meaningless, some lenders wont give you a mortgage unless you have been in full time employment for at least 6 months prior.
Let me know if you want our IFA's details.