Monday, December 20, 2010

WCF OperationContractAttribute with example

The OperationContractAttribute, also defined in the System.ServiceModel namespace, can be applied only to methods. It should declare to the method which belongs to a Service contract. Operation contract can be declared with below named parameters that provide control over the service description and message formats.

Name Specifies a different name for the operation instead of using the default, which is the method name.Action Controls the action header for messages to this operation.

ReplyAction Controls the action header for response messages from this operation.

IsOneWay Indicates whether the operation is one-way and has no reply. When operations are one-way, ReplyAction is not supported.

ProtectionLevel Enables the Service contract to specify constraints on how messages to
all operations in the contract are protected on the wire, that is, whether they are signed and encrypted.

IsInitiating Indicates whether invoking the operation initiates a new session between the caller and the service.

IsTerminating Indicates whether invoking the operation terminates an existing session between the caller and the service

Here is Sample WCF Class for reference.

// C#
[ServiceContract(Namespace = "")]
public class CrudContract
{
    [OperationContract(IsOneWay = true, Action = "urn:crud:insert")]
    void ProcessInsertMessage(Message message);
    [OperationContract(IsOneWay = true, Action = "urn:crud:update")]
    void ProcessUpdateMessage(Message message);
    [OperationContract(IsOneWay = true, Action = "urn:crud:delete")]
    void ProcessDeleteMessage(Message message);
    // The catch-all operation:
    [OperationContract(IsOneWay = true, Action = "*")]
    void ProcessUnrecognizedMessage(Message message);
}

Hope this is useful Party smile

No comments:

Post a Comment