Why do we need an Interface in Web Service ? [Resolved]

Posted by Akiii under WCF on 3/13/2012 | Points: 10 | Views : 12634 | Status : [Member] | Replies : 9
Hi friends,
When we are using WCF or normal web-service, by default an interface is created in the both the technologies. Why do we need an interface in there ? Can't we just use a Class instead of that ?

Please do share some knowledge on this matter !



Thank and Regards
Akiii




Responses

Posted by: Hmanjarawala on: 3/14/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi Akii,

in dotnet interfaces are used for describing behaviour.
WCF, Web-services and remoting this all technology uses RPC (Remote Procedure Calling) behaviour.
in RPC there must be some common binding which shared by client and server.

if you use classes instead of interface, you've share your resultatnt dll file to client also.
hence your logic goes to client side, which is not good practice. that's why we are using interfaces.


Mark this as answer, if it helps you...........

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/15/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi Akiii,

1st of all using interface as shared medium between client and service, we can hide our businesslogic from client...
here i means that if you use concrete classes then client may generate code from your dlls (through ILDASM.exe or other tools available...).
and reason for not using abstract class for same because multiple inheritance is not supported.

that's why................

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/14/2012 [Member] Silver | Points: 25

Up
0
Down
Hi, Akkiii
This link is an additional reference for you.
http://stackoverflow.com/questions/8564710/why-do-wcf-services-use-interfaces-as-a-service-contract-instead-of-an-abstract

Thanks,
Sanjay

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 3/14/2012 [Member] Silver | Points: 25

Up
0
Down
@Himanshu
Nice explanation..Keep sharing...!!!

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 3/15/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi Himanshu ,

Thanks for your answer. You want to say that through Interfaces we are describing the behaviors ?
Now when a RPC call is made, interfaces are used to connect that to our system ......it is something like that ?
the servicecontract attribute can be only applied to an interface, why not an abstract class ?

Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 3/15/2012 [Member] Bronze | Points: 25

Up
0
Down
Thanks Sanjay for your post, please refer to the questions asked above to Himanshu. If you know the answer then please do share !


Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 3/15/2012 [Member] Bronze | Points: 25

Up
0
Down
Thank you Himanshu ......for giving a good explanation !

Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: shivratankumar08-29515 on: 1/21/2015 [Member] Starter | Points: 25

Up
0
Down
WCF rules, if a class has been marked with a ServiceContract attribute then another class cannot inherit from it.

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sushilkumarmodi on: 2/1/2016 [Member] Starter | Points: 25

Up
0
Down
Hi all,
when you use abstract in WCF then compiler will not give the error. But when you run the service that time you get error like:- "Contract inheritance can only be used among interface types."

Sushil Kuamr
MPS Ltd.
Email : sushilct25@gmail.com
Blog: aspmaterials.blogspot.com

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response