Contract
Inheritance
Service contract interfaces can derive from each other, enabling
you to define a hierarchy
of contracts. However, the ServiceContract attribute is not
inheritable:
[AttributeUsage(Inherited
= false,...)]
public sealed class ServiceContractAttribute : Attribute
{…}
Consequently, every level in the interface hierarchy must
explicitly have the Service Contract attribute.
Service-side contract hierarchy
[ServiceContract]
interface IUser
{
[OperationContract]
string AddUser(string
UserName, string Pass,string
email, string firstName, string lastName)
}
[ServiceContract]
interface IAdminUser
: IUser
{
[OperationContract]
string DeleteUser(int UserID);
}
When it comes to implementing a contract hierarchy, a single
service class can implement
the entire hierarchy, just as with classic C# programming:
class User : IAdminUser
{
public
string AddUser(string
UserName, string Pass,string
email, string firstName, string lastName)
{
try
{
using
(var Context=new
MyEntities())
var
user = Context.Users.Where(c => c.UserName == UserName).FirstOrDefault();
if
(user != null)
return
"Duplicate Username.";
else
{
Users Us = new Users();
Us.UserName = UserName;
Us.Password = Pass;

Join the conversation! Your thoughts help the community grow.