As a general rule, "An opportunity attack is a melee basic attack" (Compendium glossary), so this doesn't come up much.
However, there are special cases: Ninth Legion Student [Lesser Style] lets you use Direct the Strike (ranged 5) "in place of a melee basic attack when making an opportunity attack."
Now, both the Glossary entry for Ranged Attack and the entry for Opportunity Attack explicitly say that ranged powers provoke OAs from adjacent enemies. To me, this means that ranged OAs provoke OAs unless a feat/power/item/feature explicitly lists an exception.
Conclusion: YES. Ranged attacks always provoke opportunity attacks, even when the ranged attack is itself an opportunity attack. It's really uncommon though, as using ranged attacks for OAs is a rare exception to the "only-MBAs-for-OAs" rule, and there'd have to be a second enemy adjacent to you to take advantage of the granted OA anyway. [Note: OAs interrupt the action that provoked them, so causality might get messy to track if this procs a chain of OAs.]
Generally, only willingly moving out of an enemy's reach provokes opportunity attacks
From the Basic Rules, p74:
You can make an opportunity attack when a hostile
creature that you can see moves out of your reach. To
make the opportunity attack, you use your reaction
to make one melee attack against the provoking
creature. The attack interrupts the provoking creature’s
movement, occurring right before the creature
leaves your reach.
No other situations are listed. Note that unlike previous editions, only leaving an enemy's reach provokes; moving from one position in their reach to another does not provoke. Being forced out of a creature's reach also doesn't provoke, as when pushed or falling.
Ranged attacks do not provoke; from the Basic Rules, p73:
Aiming a ranged attack is more difficult when a foe
is next to you. When you make a ranged attack with
a weapon, a spell, or some other means, you have
disadvantage on the attack roll if you are within 5 feet
of a hostile creature who can see you and who isn’t
incapacitated.
Ranged attacks have disadvantage when in melee, but do not provoke.
Spells do not provoke or suffer any other penalties for being cast in melee (other than those that require a ranged attack, which suffer disadvantage as mentioned above).
Some feats may expand how and when an opportunity attack is triggered. In these cases, the specific wording of the feat will override the general rule.
Best Answer
Yes, there is a way to way to make attacks of opportunity (AoOs from now on) using a ranged weapon. In fact, there are several, which I'm going to detail.
I'm including 3e sources in this answer, since they're still valid in 3.5e
Use a throwing weapon
Any throwing weapon can be used in melee with no penalty. This is the trivial solution.
Of course, throwing weapons have a short range increment, each "ammunition" is heavy and costy and every single weapon must be enchanted separately, making this a subpar choice for the vast majority of ranged weapon builds.
Attacks of Opportunity while wielding a ranged weapon
There are several ways to have a melee weapon ready for dealing AoOs even while you're using a two-handed projectile weapon.
The first one is being able to use a weapon with a different part of your body, including but not limited to:
When you wield a two handed weapon, including a bow, you can change your grip to just hold it in your off-hand as a free action, allowing you to attack with your free hand:
Attacks of Opportunity made with a ranged weapon
Some bows from Races of the Wild are built to double as melee weapons:
Some ways to do a ranged AoO:
These options are not guaranteed to prevent people at the right distance to make an AoO against your using a ranged weapon in melee.