WCF OperationContract
Asked Answered
S

2

21

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

Stannic answered 10/8, 2012 at 19:37 Comment(0)
D
44

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);
}
Dunstable answered 13/8, 2012 at 20:5 Comment(2)
Well, Like I need all methods to be accessed by client, and I don't want to write that on every method, what do I do there?Andreas
See #18722054Maurits
P
7

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

Peale answered 1/6, 2013 at 23:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.