WCF tutorial | WCF RIA Domain Service
Domain services are WCF services that expose the business logic of a WCF RIA
Services application. Domain service contains set of business related data
operation and it is exposed as WCF service.
Below diagram explains integration of the RIA service with WCF
The DomainService class is the base class for all classes that serve as domain services.
- DomainServiceHost is the hosting class for domain service; internally
- DomainServiceHost uses the WCF ServiceHost class to host the application.
A domain service class must be marked with the EnableClientAccessAttribute
attribute to make the service available to the client project. The
EnableClientAccessAttributeattribute is automatically applied to a
domain service when you select the Enable client access
check box in the Add New Domain Service Class dialog
box. When the EnableClientAccessAttribute attribute
is applied to a domain service, RIA Services generates the corresponding classes
for the client project.
public class EmployeeDomainService : DomainService
private EmployeeData data = EmployeeData.Instance;
public IEnumerable < Employee> GetEmployees()
DomainContext class at the client side is used to consume the Domain service by using DomainClient object. DomainContext class available inside the name space "System.ServiceModel.DomainServices.Client"
fig: WCF RIA Domain Serive architecture
- Always create the service with Interface->Implementation format, mention the contract in Interface.
- Define the service in Class library and refer the class library in Host project. Don’t use service class in host project.
- Change the instance mode to per call as default.
- Always catch exception using try/catch block and throw exception using FaultException < T >.
- Logging and Include exception should be enable while compiling the project in debug mode. While in production deployment disable the logging and Include exception details.