6
Answers

Why are used in wcf for interface concept

Guddoo Chauhan

Guddoo Chauhan

12y
5.6k
1
All ready provide interface and abstract class concept in c# . but im create servics i am used interface for creating service i am not used abstract class and class.
Answers (6)
3
Akkiraju Ivaturi

Akkiraju Ivaturi

NA 9.5k 2.5m 12y
As I understand why are we using interfaces for services not the classes rt? The basic concept of SOA is a service should only expose what are the operations it is going to support, not the internal details (schema). So, when ever we create a proxy of the service, we refer to the interface in stead of service class.

Basically we need to look into following aspects to find out why:

1. Interfaces provides you the skelton of all the methods that the service class supports (in oops, any class that implements the interface should implement all the methods of the interface and any can implement many interfaces, but can inherit only one class).
2. If you version the services, interfaces are the best way to handle the versioning of services.
You can refer to my article on versioning http://ilovemicrosoft.blogspot.com/search/label/WCF%20service%20versioning
3. Abstract classes may have non abstract methods so to be pure abstract entity interface is the correct way of implementation.
0
sushil kumar

sushil kumar

NA 606 10.8k 9y
In dotnet intserfaces are used for describing behaviour.
WCF,Web Service and remoting this all technology uses RPC(Remote Procedure Calling) behaviour.

Abtract class not used because class not support multiple interface.
In WCF rules, If a clas has been marked with a ServiceContract attribute then another class cannot inherite from it.

Example:-
Just make a simple service for adding and subtracting nos.

[ServiceContract]
Public abstract class MathAbstract
{
   [OperationContract]
   Public Abstract Int Substract(int num1,int num2);
   
   [OperationContract]
   Public Abstract Int Add(int num1,int num2);
   

}


Public Class Math:MathAbstract
{
   public Override int Add(int num1, int num2)
   {
       return num1 + num2;
   }
   
   public Override int Subtract(int num1, int num2)
   {
       return num1 - num2;
   }
}


Please run this service then you will get the error :- 
"The service class of type Service both defines a ServiceContract and inherits a ServiceContract from type IService. Contract inheritance can only be used among interface types.  If a class is marked with ServiceContractAttribute, then another service class cannot derive from it."

So that we are using Interface in WCF.
0
I am asking why we should interface in wcf rather then abstract class
0
Akkiraju Ivaturi

Akkiraju Ivaturi

NA 9.5k 2.5m 12y
Can you please mark the answer as accepted?
0
Guddoo Chauhan

Guddoo Chauhan

NA 66 5.6k 12y
Thanks for Reply , I am satisfied this answer;
0
Hemant Srivastava

Hemant Srivastava

NA 9k 2.8m 12y
You mean, how to create Interface in wcf ? OR why they are used? I didnt get.. Could you make it more clear... I can help you