![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
a using System.ServiceModel; namespace com._80community.unittest.Demo { / * * [ServiceContract] Service Definition agreement * [ServiceContract] This feature tells the compiler, the type (refer to IAnimal) is a service contract * * / [the ServiceContract] public interface IAnimal { / * service method * [OperationContract] to open * [] represents the characteristics inherited from class System.Attribute class, in fact, features and comments. Similarly, is used to describe the assembly, type, members of the "Remarks Information", and notes the difference is: Comments are to "human" look, while the feature is to "compiler" to see * [OperationContract] This feature tells compiler, the member (refer to Function1) is an operating contract, so when programming with reflection mechanism can determine what type of labeled service contract, which members marked operating contract in WCF will find these do service * [OperationContract] what code will execute his sentence in the WCF, will identify the characteristics of all members of OperationContract mark as a service * / [OperationContract] string Behavior(); } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
namespace com._80community.unittest.Demo { public class Dog: IAnimal { public String Behavior () { return " . I sleep during the day, at night housekeeping " ; } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
namespace com._80community.unittest.Demo { public class Cat: IAnimal { public String Behavior () { return " I sleep during the day, night out catch mice. " ; } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
namespace com._80community.unittest.Demo { public class Mouse: IAnimal { public String Behavior () { return " I sleep during the day, night out looking for food to eat. " ; } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[TestMethod] public void test9 () { Dog Dog = new new Dog (); var A = dog.Behavior (); // I sleep during the day, at night housekeeping. CAT CAT = new new Cat (); var b = cat.Behavior (); // I sleep during the day, come out at night to catch the mouse. Mouse Mouse = new new Mouse (); var c = mouse.Behavior (); // I sleep during the day, night out looking for food to eat. // }