Apply the OperationContractAttribute to a method to indicate that the method implements a service operation as part of a service contract (specified by a ServiceContractAttribute attribute).
Use the OperationContractAttribute properties to control the structure of the operation and the values expressed in metadata:
The Action property specifies the action that uniquely identifies this operation. WCF dispatches request messages to methods based on their action.
The AsyncPattern property indicates that the operation is implemented or can be called asynchronously using a Begin/End method pair.
The HasProtectionLevel property indicates whether the ProtectionLevel property has been explicitly set.
The IsOneWay property indicates that the operation only consists of a single input message. The operation has no associated output message.
The IsInitiating property specifies whether this operation can be the initial operation in a session.
The IsTerminating property specifies whether WCF attempts to terminate the current session after the operation completes.
The ProtectionLevel property specifies the message-level security that an operation requires at run time.
The ReplyAction property specifies the action of the reply message for the operation.
The OperationContractAttribute attribute declares that a method is an operation in a service contract. Only methods attributed with the OperationContractAttribute are exposed as service operations. A service contract without any methods marked with the OperationContractAttribute exposes no operations.
The AsyncPattern property indicates that a pair of Begin<methodName> and End<methodName> methods form a single operation implemented asynchronously (whether on the client or the service). The ability of a service to implement operations asynchronously is a service implementation detail and is not exposed in metadata (such as Web Services Description Language (WSDL)).
Similarly, clients can choose to invoke operations asynchronously independent of how the service method is implemented. Calling service operations asynchronously in the client is recommended when a service method takes some time but must return information directly to the client. For details, see AsyncPattern.
The IsOneWay property indicates that a method does not return any value at all, including an empty underlying response message. This type of method is useful for notifications or event-style communication. Methods of this kind cannot return a reply message so the method's declaration must return void.
Note: |
|---|
If the IsOneWay property is set to false, (the default), even methods that return void are two-way methods at the underlying message level. In this case, the infrastructure creates and sends an empty message to indicate to the caller that the method has returned. Using this approach enables the application and the infrastructure to send error information (such as a SOAP fault) back to the client. Setting IsOneWay to true is the only way to prevent the creation and dispatch of a reply message. For more information, see One-Way Services. |
The Action and ReplyAction properties can be used not only to modify the default action of SOAP messages but also to create handlers for unrecognized messages or to disable adding actions for direct message programming. Use the IsInitiating property to prevent clients from calling a particular service operation prior to other operations. Use the IsTerminating property to have WCF close the channel after clients call a particular service operation. For more information, see Using Sessions.
The ProtectionLevel property enables you to specify on the operation contract whether the operation messages are signed, encrypted, or signed and encrypted. If a binding cannot provide the security level required by the contract, an exception is thrown at run time. For more information, see ProtectionLevel and Understanding Protection Level.