Is it necessary for me to write [OperationContract] over every method in my WCF Service?
For example, is this correct?
[OperationContract]
bool IsHappy(string userID);
bool IsSad(string userID);
bool IsHungry(string userID);
Is that a valid body of operations for a WCF ServiceContract or do I ha开发者_如何学Pythonve to do it this way:
[OperationContract]
bool IsHappy(string userID);
[OperationContract]
bool IsSad(string userID);
[OperationContract]
bool IsHungry(string userID);
You must denote every method that you want to expose from the service with [OperationContract]
. You are free to have methods without this attribute in your service class but those methods will not be exposed in the service metadata and will not be accessible to the client.
If all three methods are part of the service contract then all three must have an [OperationContract]
attribute - your second example is correct.
精彩评论