Praise be to Allah.
There are several phrases in your question that we should stop and think about, and we hope that you did not intend what they really mean, such as your saying, “It is as if I am in the wrong body”! This is a serious statement that undermines faith, if the one who says it really believes it. The same applies to your words “Or what did I do in the time before this world, before I was born, to be punished in this manner?” Is a test from Allah – assuming that this is what it is – a punishment from Him to the one He created? And the most serious matter is the language in your question, which is indicative of discontentment with the decree of Allah, may He be exalted, and with His directing and control of affairs; this is an implicit criticism of His perfect wisdom in what He creates. What you must do is repent from everything that you have said that oversteps the mark, and you should regret it and resolve not to go back to it. You should also think carefully about what you are saying, and ensure that your belief in your Lord and in His Lordship is correct and you should accept His will and decree.
Muslim narrated in his Saheeh (34) from al-‘Abbas ibn ‘Abd al-Muttalib (may Allah be pleased with him) that he heard the Messenger of Allah (blessings and peace of Allah be upon him) say: “He has found the taste of faith who is content with Allah as his Lord, Islam as his religion and Muhammad (blessings and peace of Allah be upon him) as his Prophet.”
What appears to be the case is that your situation is not one of a physical problem that requires “gender correction surgery” – for more information, please see the answer to question no. 164232 – rather, it is a psychological matter, which is called confusion in sexual identity. This is how doctors and psychologists refer to cases in which individuals suffer discomfort or anxiety regarding the gender with which they were born. One of the most significant causes of this problem is the family and the home environment in which the child – male or female – grows up in the beginning of his life.
What we advise you to do is to consult a female psychologist who is trustworthy in terms of her knowledge and religious commitment, and discuss your situation with her. If that is accompanied by fulfilling Islamic duties, reciting the adhkar of the day and night, and offering supplication with all sincerity, then there is the hope that you will rid yourself of this anxiety altogether, and you will be at peace with your femininity, and your anxiety about marriage will be a thing of the past, by Allah’s leave and with His help.
And Allah knows best.