Service contract describes the operation that service provide. A
Service can have more than one service contract but it should have at
least one Service contract.
Service Contract can be define using [ServiceContract] and
[OperationContract] attribute. [ServiceContract] attribute is similar
to the [WebServcie] attribute in the WebService and [OpeartionContract]
is similar to the [WebMethod] in WebService.
- It describes the client-callable operations (functions) exposed by the service
- It maps the interface and methods of your service to a platform-independent description
- It describes message exchange patterns that the service can have
with another party. Some service operations might be one-way; others
might require a request-reply pattern
- It is analogous to the element in WSDL
To create a service contract you define an interface with related
methods representative of a collection of service operations, and then
decorate the interface with the ServiceContract Attribute to
indicate it is a service contract. Methods in the interface that should
be included in the service contract are decorated with the OperationContract Attribute.
public interface IService
int Add(int num1, int num2);
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service" in code, svc and config file together.
public class Service : IService
public int Add(int num1, int num2)
return num1 + num2;
protected void Button1_Click(object sender, EventArgs e)
Service srv = new Service();
int a = srv.Add(12, 13);