Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF OperationContract

Tags:

What is a WCF OperationContract? I dont really understand what it does

like image 749
Obsivus Avatar asked Aug 10 '12 19:08

Obsivus


2 Answers

WCF uses an opt-in model to define what belongs to one of its contracts. In a service contract interface, only methods decorated with [OperationContract] are exposed to the client. That means that, in the interface below, if used within a WCF service, a client could call both Add and Subtract operations, but not Multiply.

[ServiceContract]
public interface ICalculator
{
    [OperationContract]
    int Add(int x, int y);

    [OperationContract]
    int Subtract(int x, int y);

    // Not decorated
    int Multiply(int x, int y);
}
like image 63
carlosfigueira Avatar answered Oct 24 '22 07:10

carlosfigueira


Every method you want to be able to the user calling from his client side must be declared like that.

like image 42
Bruno Willian Avatar answered Oct 24 '22 07:10

Bruno Willian