0

With out creating the interface, we can also directly created the service by placing Contract in the implemented class.So why we create Interfaces in WCF.

[ServiceContract()]
public class SimpleCal
{
  [OperationContract()]
  public int Add(int num1, int num2)
  {
    return num1 + num2;
  }
}

Update "Why do I want to avoid using an Interface ? What would be the advantage to use a class only ?"

angfreak
  • 993
  • 2
  • 11
  • 27
  • I have read that article but i am not satisfied that 'WCF completely decouples the client from the service, if you specify the implementation of the service as the service you have tightly coupled your client to the service.' what is it mean?? – angfreak Oct 10 '13 at 08:17

1 Answers1

0

Simple Answer: No.

The use of the interface is a general development good practice. It is enforced here because the ServiceContract is just a "declaration" of what the service provides to the clients in terms of "methods". The implementation has nothing to do with it, therefore, there is no need to "couple" the implementation to the service contract.

Also, if you look at the definition of an interface (source):

[...] the term "interface" is often used to define an abstract type that contains no data, but exposes behaviors defined as methods.

This is exactly what a ServiceContract does. The real question to ask yourself should be:

"Why do I want to avoid using an Interface ? What would be the advantage to use a class only ?"

Additional note: if you want to see one of the most useful (in my opinion) applications of interfaces, you should have a look at this: http://martinfowler.com/articles/injection.html

Superzadeh
  • 1,106
  • 7
  • 23