I have a piece of code - how can I make it a web service - haw can I make it?
There are different solutions based on which programming language you are using. It also depends on expected number of users. If you plan to have more than >1000 calls a day, you should probably think about production servers instead of simple scripts.
Make your web service WS-I compliance
To turn a command line application into SOAP server use Soaplab
Possibility of adding REST interface to existing websites is available in most of the web frameworks