Introduction: What is interface in Dot Net ? How it is used in WCF Services?
An interface looks like a class, but it has no implementation. It contains:-
-
Definitions of events, indexers, methods and properties.
-
An interface inherited by classes.
-
An interface defined with keyword "interface".
-
In WCF, we use interface inside the [ServiceContract] attribute.
-
Interfaces don't have their own objects.
What are the benefits of using interface in our WCF application?
-
Interfaces can extend/inherit other interfaces .
-
A single class can implement multiple interfaces .
-
You can modify the implementation of a service without breaking the contract .
Code:
[ServiceContract]
Public
Interface
IHello
{
[OperationContract]
string
HelloWorld();
[OperationContract]
string
HelloComputer();
}
public
class Hello :
IHello
{
string
IHello.HelloWorld()
{
return
"Hello world";
}
string
IHello.HelloComputer()
{
return
"Hello computer";
}
}
santosh chougulePosted Sep 21, 2011, 9:19 AM
Very nice description Please give the full example of points so user can understood detail, Thank you.