Hi,
What is the difference between Service Contracts and Operation Contracts in WCF? Explain with some example.
Thanks.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Posted Sep 20, 2011, 8:39 PM EDT
Where as,Operation Contract means it is the name of the attribute which is applied to a method inside the interface of a wcf service which is similar to the [WebMethod] in WebService.
this means, ServiceContract attribute is similar to the [WebServcie] attribute in the WebService and [OpeartionContract] is similar to the [WebMethod] in WebService.
Example :
[ServiceContract()]
public interface IFullname
{
[OperationContract()]
String Add(string FirstName, string Lastname);
}
Once we define Service contract in the interface, we can create implement class for this interface.
public class Fullname : IFullname
{
public String Add(string FirstName, string Lastname)
{
return FirstName + Lastname;
}
}
Pravin MoreRank #1,419 · 1.2K reputationPosted Sep 20, 2011, 8:46 PM EDT
basic about ServiceContract and OperationContract is.....
ServiceContract:-
service contract is at Class ans Interface Level.You can Define Classes and Interfaces in [ServiceContract] like below....
public namespace WCF_Service
{
[ServiceContract]
public class Sevice Class
{
}
}
Operation Contract:-
Operation contract is at Operation Level(Function).You can Define Methods in [OperationContract] like below.... and Opeation Contract can have [MessageContract] also.....
public namespace WCF_Service
{
[ServiceContract]
public class Sevice Class
{
[OperationContract]
public getData()
{
//Some Code
}
}
}
this is basuc about service and operation contract...hope it will help you.
Thanx,
Pravin.