We've several (5+) programs that hit exactly the same database and we are encountering issues in which the programs all go to their own hands to construct queries that fetch exactly the same data. However, since different designers are coming up with these queries they are not identical as they must be, thus coming back spun sentences every so often.

So far as I can tell you will find 2 possible solutions.

  1. Produce a library that every application references to obtain the proper query
  2. Produce a WCF service that encapsulate common queries utilized by each application and make up a client for every application to make use of

I am leaning towards option 2 because this gives us the versatility to change filters we are using within our queries, thus upgrading each application at the same time.

The service hierarchy would look something similar to

public class QueryService
{
    private readonly IRepository _repository;

    public QueryService(IRepository repository)
    {
        _repository = repository;
    }

    public IEnumerable<int> GetCommonOperation()
    {
        return _repository.GetCommonOperation();
    }

    public IEnumerable<AnotherDto> AnotherCommonOperation()
    {
        return _repository.AnotherCommonOperation();
    }
}

Then produce a client that will communicate with QueryService.

So my question what's the general method for creating querying services using the sole goal of encapsulate generally used queries/procedures for many programs?

You've already clarified your personal question. Basically, you need to seperate the interface in the implementation, just like an internet service (or WCF) would accomplish. Should you create an set up, you will still must make sure the set up is used together with your seperate clients, or at best someplace that's accessible by any application deploying it. Appears like much more work. However, bear in mind, if one makes changes towards the service signatures, any client utilizing that service can also get to update to mirror the brand new definitions.

The truly amazing factor in regards to a web service (WSDL) is the fact that it's generic. You are able to write the client's in almost any language that may consume and parse WSDL -- unlike an set up, where you'd be focusing on a particular build or OS. So whether you've C#, Java, iOS, Android, etc. clients, they all are capible of employing the services you provide.