Data Transfer Classes in SOA
My WebApplication calls WebService methods to perform CRUD operations on the database.
All of the methods in the WebService, get inputs as request classes, and return output as response classes. e.g:
if i want to get a Customer from Customer table, then method to use in WebService is:
CustomerResponse GetCustomer(CustomerRequest request)
CustomerRequest contains the properties, such as ID; which will then be used to get the customer by that ID from DB.
CustomerResponse con开发者_JAVA百科tains all the properties that i want to pass to the WebApplication, such as ID, Name, Address
So Far, So Good ...
if i want to get all of the customers, i have to create 2 extra classes for that, one as in: CustomersRequest and the second CustomersResponse. so in total i have 4 data transfer classes:
CustomerRequest CustomerResponse CustomersRequest CustomersResponse
where CustomersResponse has a property List which contains all of the CustomerResponse objects.
is it a good approach, or should this be done in 2 classes, whether we want a collection or individual objects of a particular class?
because if i keep doing this every table in the db will at least end up with 4 classes.
Good approach to use REST-based CRUD interfaces. SOA interfaces should be more specialized.
I guess these are some guidelines in developing SOA applications. The fundament is to maintain your business separate objects that represent business from the objects in the contract that the services expose.
Refer to the SOA patterns Standardized Service Contract and Concurrent Contracts
EDIT
The correct answer is, "depends on the contract you wish to expose."
I believe you should still define two:
Internally, you could maintain a single implementation <xs:complexType name="CustomersResponse">
<xs:sequence>
<xs:element name="Customer" minOccurs="1" maxOccurs="unbounded" />
<!-- other fields -->
</xs:sequence>
</xs:complexType>
<xs:complexType name="CustomerResponse">
<xs:sequence>
<xs:element name="Customer" minOccurs="1" maxOccurs="1" />
<!-- other fields -->
</xs:sequence>
</xs:complexType>
List<Customer>getCustomers(query);
that picks up a list. From this result, you could map your internal service response to these objects.
精彩评论