There are a few "methods" that you can use to write solos, but it's mostly just a matter of feeling it.
Most bands like to follow the melody of the song a little bit and then expand on that theme with the solo. But the main point is that the solo should match the mood and feel of the song while adding to it. The solo usually serves as the climax for the song, so it should take it little bit from the melody and add some lines to keep it interesting.