The major goal of a melody is to be remembered, and to be expressive of some feeling.
The minor goal of a melody is a flatted third (it was funny, stop lacking a sense of humor and admit it).
One of the major goals of a solo is to seamlessly play through the chord changes, i.e. CAGED. However, this won't necessarily produce a lasting effect. A sense of direction, memorable motifs, etc. are important for developing a good melody.
I was watching a video today where the guy was talking about composing for classical guitar. He mentioned to write the melody first and then establish the chords behind it. Thus it would be derived from a scale, not a chord progression. Modal jazz where they stay on one chord for a long period of time is a good example for this: it make melodic improvisation easier. However, after the chord progression has been decided upon, you have to follow the chords--to a degree. It is not necessary to only arpeggiate the chords only higher up the neck, nor to play off of the chord shapes (although mastery of these things should come before melodic improvisation), but you also shouldn't just "play notes from a scale." The notes have to follow in some way with the chords (i.e. emphasize the 1, 3, 5, and all that kind of stuff).
Melodic improvisation started to click a little while ago for me. I had been practicing singing intervals while ear-training, and then while I was playing a solo, I began to hear the rest of the phrase before I decided what I was about to play. Trippy, man.
They say it is easier to sing a good melody than to play one (assuming one has the vocal ability to stay reasonably within a scale). Most people to sing a sound they hear in their head better than they can translate the sound into their instrument.
Question to some of the more experienced musicians: Does any of this seem right?