How to connect to drupal 7 using web service? can I connect to my Drupal website using web services and pass a variable (with post method) to it? I know that forms in Drupal actually have hidden elements so that it is not possible to submit the form from external sources. 

There is also a service module but I don't think I can achieve what I am trying to do with it.

The following is what I am trying to do with Drupal:

When I connect to www.drupal-site.com/web-service (web-service is just an example), I would like to be able to post variables to it and perform complex database queries. I would also like to return the result of the queries in json (using echo maybe). I would also like to be able to remove the headers and footers of my drupal site.

I really need some direction on how this can be achieved.
Your use case can be achieved using Services module easily.

All you need to do is write a hook_service() 

refer http://drupal.org/node/118126 Or just look into the services module's any child module, may be user_services. 

Do this,


Write a service that exposes all your query parameters as fields.
Accept these parameters into your web service callback and perform your business logic.
Return your results, this is just a return statement, no JSON conversion here. 
ex: return $output. 
//$output contains your array or data structure that you have as a result of your queries.


Now, how to convert the data to JSON. ?

Services module will provide you intermediate servers,  XML-RPC, JSON. (these are by default, there are more avaialable on drupal.org). These servers function as end points to whom you can connect using external applications or entities. ex: http://www.domain.com/services/json.

Thats it, the flow will be,


You connect to the endpoint, URL http://www.domain.com/services/json. Pass the data in JSON.
the JSONserver will convert that into PHP and will pass it to your web service callback.
You do the processing and return the data to the web service in PHP.
The server converts the data into JSON again.
This is handed over to the HTTP request that requested the processing in the first place.