You can adhere to four service principles to ensure better designed services. These are known as the Four Tenets of SOA, and they are explained in the following sections.

 

Boundaries are explicit

A service interface needs to be as clean and simple as possible and have a consistent approach to the exchange of data, often referred to as messages. It is also a good idea to keep a service’s API small and clear, favoring coarse-grained methods rather than a host of finer-grained methods. You will see later in the “Leveraging Messaging Patterns” section how a number of patterns can be used to create clean and clear service methods. 

services are autonomous

 Service methods should be loosely coupled and not rely on other methods to perform a business transaction; a client should not be required to call methods in a particular order to perform a business transaction. A client should be able to invoke a single service and within one atomic action receive a response on the success or failure of that transaction. Service methods should also be stateless and not leave a system in a partially done state before another service is called to complete a request. 

services share schema and Contract, not Class

One of the goals of SOA is interoperability; to this end a service should only expose a contract, not the implementation of the service. Communication is achieved via XML, also known as messages; these are platform neutral and help to achieve interoperability.

service Compatibility is Based on Policy

A service should expose a policy on what it can be used for. Clients can then consume a service with good knowledge of how to use it and what to expect in terms of response. Information on what a service does can be exposed using the WS-Policy specification; the WS-Policy represents a set of specifications that describe the capabilities and constraints of the service.If you are still finding the SOA design methodology a little abstract, there is a large exercise at the end of this chapter that uses WCF to build a SOA. This should help to cement the main points of SOA.This has only been a brief overview of SOA. For a more in-depth look at SOA, take a look at SOA Design Patterns and/or SOA Principles of Service Design by the SOA guru Thomas Erl.In the next section you will learn how one of the Gang of Four patterns can be used in the service layer of an enterprise ASP.NET application.