How to: Add Business Logic to the Domain Service
Last updated
Was this helpful?
Last updated
Was this helpful?
[ This document was written for WCF Services Version 1 Service Pack 2 and might not be up to date Please see or for a list of changes since WCF RIA Services ]
In this topic, you will learn how to add business logic to a domain service in a Open Ria Services application. A Open Ria Services domain service contains update, insert, and delete methods by default, but you often need to add additional business logic that modifies the data. You may also need to add methods that perform operations that are not the traditional query, update, insert, or delete methods. In this topic, you will learn how to modify data operations to meet business requirements. You will also learn how to add a named update method and an invoke operation.
Create the update, insert, or delete methods that you need in your application.
You create these methods either by selecting Enable editing when generating the domain service in the Add New Domain Service Class dialog box, or by adding the methods that match the expected signature for the operation. For more information, see .
In the update, insert, or delete methods, add code that specifies the logic for processing the request.
Add any additional methods that are required to meet the business requirement. Mark with the attribute if you do not want the method exposed as a service.
The following example shows an insert method that assigns the salesperson if one is not assigned. The RetrieveSalesPersonForCompany method retrieves the name of the salesperson for a company if a customer from that company is in the database. The method is marked with the attribute to prevent the method from being called as a service from the client.
In the domain service class, add a method that matches the expected signature for a named update method.
The following example shows a method that allows a user in the CustomerRepresentative role to reset a customer's password.
The following example shows a method that retrieves the local temperature based on postal code.
The method should either be marked with the attribute with the property set to true, or not return a value and accept an entity as the first parameter.
When you add a named update method, two methods are generated in the client project. One method is generated on the domain context and one method is generated on the entity that is passed as a parameter for the named update method. You execute this named update method from the client by calling either the generated method on the domain client or the generated method on the entity. After calling either method, you must call the method, as shown in the following code.
In the domain service class, add a method that is marked with the attribute.
You call the method by using an object, as shown in the following code.