OperationDescription Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Represents the description of a contract operation that provides a description of the messages that make up the operation.

Namespace:   System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)


Public Class OperationDescription

System_CAPS_pubmethodOperationDescription(String, ContractDescription)

Initializes a new instance of the OperationDescription class with a specified name and contract description.


Gets or sets the begin method of the operation.


Gets or sets the operation behaviors associated with the operation.


Gets or sets the contract to which the operation belongs.


Gets or sets the end method of the operation.


Gets the descriptions of the faults associated with the operation description.


Gets a value that indicates whether the operation has had a protection level set.


Gets or sets a value that indicates whether the method implements an operation that can initiate a session on the server (if such a session exists).


Gets or sets a value that indicates whether an operation returns a reply message.


Gets or sets a value that indicates whether the service operation causes the server to close the session after the reply message, if any, is sent.


Gets the known types associated with the operation description.


Gets or sets the descriptions of the messages that make up the operation.


Gets or sets the name of the operation description.


Gets the set of behaviors for the operation.


Gets or sets the protection level for the operation.


Gets or sets the service synchronization method of the operation description.


Gets or sets the method used for the task operation.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a value that indicates whether the ProtectionLevel property has changed from its default value and should be serialized.


Returns a string that represents the current object.(Inherited from Object.)

A Windows Communication Foundation (WCF) contract is a collection of operations that specifies what the endpoint communicates to the outside world. Each operation is a message exchange. For example, a request message and an associated reply message forming a request/reply message exchange.

A ContractDescription object is used to describe contracts and their operations. Within a ContractDescription, each contract operation has a corresponding OperationDescription that describes aspects of the operation, such as whether the operation is one-way or request/reply. Each OperationDescription also describes the messages that make up the operation using a collection of MessageDescription objects. ContractDescription contains a reference to an interface that defines the contract using the programming model. This interface is marked with ServiceContractAttribute, and its methods that correspond to endpoint operations are marked with OperationContractAttribute.

Many of the properties on OperationDescription have corresponding properties in the WCF programming model on OperationContractAttribute, for example, IsTerminating.

The following example uses the OperationDescription returned from the collection returned by the Operations property of the ContractDescription class. The code iterates through the collection of endpoints and prints each endpoint name, as well as the name of each operation in the endpoint.

Private Sub PrintDescription(ByVal sh As ServiceHost) 
    ' Declare variables.
    Dim i, j, k, l, c As Integer
    Dim servDesc As ServiceDescription = sh.Description
    Dim opDesc As OperationDescription
    Dim contractDesc As ContractDescription
    Dim methDesc As MessageDescription
    Dim mBodyDesc As MessageBodyDescription
    Dim partDesc As MessagePartDescription
    Dim servBeh As IServiceBehavior
    Dim servEP As ServiceEndpoint

    ' Print the behaviors of the service.
    For c = 0 To servDesc.Behaviors.Count-1
        servBeh = servDesc.Behaviors(c)
        Console.WriteLine(vbTab + "{0}", servBeh)
    Next c

    ' Print the endpoint descriptions of the service.
    For i = 0 To servDesc.Endpoints.Count-1
        ' Print the endpoint names.
        servEP = servDesc.Endpoints(i)
        Console.WriteLine(vbTab + "Name: {0}", servEP.Name)
        contractDesc = servEP.Contract

        Console.WriteLine(vbTab + "Operations:")
        For j = 0 To contractDesc.Operations.Count-1
            ' Print operation names.
            opDesc = servEP.Contract.Operations(j)
            Console.WriteLine(vbTab + vbTab + "{0}", opDesc.Name)
            Console.WriteLine(vbTab + vbTab + "Actions:")
            For k = 0 To opDesc.Messages.Count-1
                ' Print the message action. 
                methDesc = opDesc.Messages(k)
                Console.WriteLine(vbTab + vbTab + vbTab + _
                  "Action:{0}", methDesc.Action)

                ' Check for the existence of a body, then the body description.
                mBodyDesc = methDesc.Body
                If mBodyDesc.Parts.Count > 0 Then
                    For l = 0 To methDesc.Body.Parts.Count-1
                        partDesc = methDesc.Body.Parts(l)
                        Console.WriteLine(vbTab + vbTab + _
                        vbTab + vbTab + "{0}", partDesc.Name)
                    Next l
                End If
            Next k
        Next j
    Next i

End Sub     

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top