Why OperationContract attribute required in WCF service function?
+2
A:
The OperationContact attribute explicitly declares that a method is an operation on a ServiceContract.
Why is it required? The main reason is that most of WCF is opt-in and this is no different. WCF does not assume that simply because a method is part of an interface that you want to expose that method as a service operation. It is left to the programmer to decide (and explicitly indicate) what they want to expose.
Tuzo
2009-09-08 04:43:08
hmm..so you mean that this attribute should be applied to the methods whatever we want to expose from the service?
Jaswant Agarwal
2009-09-08 04:52:12
WCF uses a "you tell me explicitly what you want to do" approach, which I strongly believe is a GOOD thing. You need to explicitly tell WCF what you want exposed - thereby clearly stating your intent, and that makes it easier for someone else to understand your intentions.
marc_s
2009-09-08 04:55:09
yea..this definition is exact wcf approach..but technically i want to know about the functionality of OperationContract attribute
Jaswant Agarwal
2009-09-08 05:04:39
What type of functionality? OperationContract lets you override default settings which affect how your service is exposed. The attribute is also used by the WCF runtime to expose your service to consumers (e.g. WSDL) and for dispatching incoming messages to the associated operation (CLR method).
Tuzo
2009-09-08 05:26:28
Am I wrong here in that after 3.5 SP1 it looks like OperationContract is completely optional and public methods were included in my service contracts regardless of whether this attribute was present???
David Andres
2009-09-08 05:47:45