This is the first time i spend time to read about WCF, even thought it has been there for long time. And i have just finished chapter 1 🙂 . With the OOP in mind, since i have been working with OOP quite long enough, i got surprised with the advise from the book:
DO NOT THINK IN OOP WAY, IN DOCUMENT INSTEAD.
So what are behind the scene here? WCF is SOA ( Service Oriented Architect), everything is seen as contract and message. Whereas, OOP is the way we build our object model to solve the business needs.
Summary of some keys word:
- To define a service: Mark interface with ServiceContract attribute, always remember to give it a Name and Namesapce as best practice.
- To define a function: Mark the function with OperationContract, in case of throwing exception, an FaultException object, then FaultContract attribute is require. Remember that never use this property for OneWay operation.
- To define a class containing data sent through the service: Mark class/enum with DataContract attribute, mark each member to be serialized with DataMember or EnumMember
In case of you really need to make an inheritance and the return type is for base class, for instance, Task class. And you have a class ApprovalTask inherited from Task. Consider the situation you want to return a collection of Task, and there are some ApprovalTask. THEN, the Task class must be decorated with KnowType(typeof(ApprovalTask)) attribute.
Continue reading ….