In order to receive text messages, you need a service provider to provide you this service. By service provider I mean a company that provides a short code service or sms gateway. They will then be able to hit a webservice of yours with the relevant data, but that will depends on the provider and your needs
Incoming SMS processing is a lot more expensive than outgoing, which can be done on a pay as you go basis for not much. For incoming, you'll typically pay a set up fee, a monthly subscription and additional charges per received message. Have a look at well known providers like clickatell for pricing and API integration examples.