C# – Naming convention for C# class that accesses a webservice

cnaming-standardsweb services

I apologize if this is a little vague, but I'm curious about what most people use for naming conventions for classes that access a webservice. Typically on my team we create separate projects for BLL (business rules), Model (DTOs and ASP.NET model classes), and Data ( typically Db and WS I/O ).

My question is in regards to what teams do for classes that access services. Typically in our Data project we postpend 'Dao' to the class name that queries the objects in the Db. So for example a class that does CRUD operations in a Db on Foo objects we typically name FooDao.cs and there seems to be general consensus on the team for that pattern. But what do teams do for classes that query webservices? Sometimes we name them as FooFacade.cs, or FooSvcClient, or even FooSvc.

I understand there probably isn't a true right or wrong answer here, but I want to know what others do, and if there is momentum towards a particular approach.

Best Answer

Code that accesses a service is generally called a "Client."

Since class names should be descriptive, the name of your class should probably include the word "client," since that's what the class is. You can make that moniker as descriptive as you like: JsonWebServiceClient, for example.

In addition, I think it would be useful if the class name also included the name of the type being retrieved, or a description of the operation being performed. So, for example, if you were retrieving a Customer object from a json web service, your class name might be

CustomerClient
CustomerWebServiceClient

or even

CustomerXmlWebServiceClient

To add some weight to these assertions, here is an example from ServiceStack.Client, a library that allows you to write generic clients against XML and JSON web services:

enter image description here

Notice how the name of the client class is XmlServiceClient, and the Post method accepts the expected return type as a parameter.

Whatever you do decide, make sure that the naming convention you settle upon is agreed upon by the team and then strictly followed. The cost of whatever convention you do adopt is 2 minutes with each new developer explaining how it works, or documentation to that effect.

Related Topic