共用方式為


MessageDescription 類別

定義

表示訊息的描述。

public ref class MessageDescription
public class MessageDescription
type MessageDescription = class
Public Class MessageDescription
繼承
MessageDescription

範例

下列範例會使用從 MessageDescription 類別 Messages 屬性傳回的 OperationDescription。 此程式碼會逐一查看端點的集合,並列印每個端點名稱以及端點中每個作業的名稱。

private void PrintDescription(ServiceHost sh)
{
    // Declare variables.
    int i, j, k, l, c;
    ServiceDescription servDesc = sh.Description;
    OperationDescription opDesc;
    ContractDescription contractDesc;
    MessageDescription methDesc;
    MessageBodyDescription mBodyDesc;
    MessagePartDescription partDesc;
    IServiceBehavior servBeh;
    ServiceEndpoint servEP;

    // Print the behaviors of the service.
    Console.WriteLine("Behaviors:");
    for (c = 0; c < servDesc.Behaviors.Count; c++)
    {
        servBeh = servDesc.Behaviors[c];
        Console.WriteLine("\t{0}", servBeh.ToString());
    }

    // Print the endpoint descriptions of the service.
    Console.WriteLine("Endpoints");
    for (i = 0; i < servDesc.Endpoints.Count; i++)
    {
        // Print the endpoint names.
        servEP = servDesc.Endpoints[i];
        Console.WriteLine("\tName: {0}", servEP.Name);
        contractDesc = servEP.Contract;

        Console.WriteLine("\tOperations:");
        for (j = 0; j < contractDesc.Operations.Count; j++)
        {
            // Print the operation names.
            opDesc = servEP.Contract.Operations[j];
            Console.WriteLine("\t\t{0}", opDesc.Name);
            Console.WriteLine("\t\tActions:");
            for (k  = 0; k < opDesc.Messages.Count; k++)
            {
                // Print the message action.
                methDesc = opDesc.Messages[k];
                Console.WriteLine("\t\t\tAction:{0}", methDesc.Action);

                // Check for the existence of a body, then the body description.
                mBodyDesc = methDesc.Body;
                if (mBodyDesc.Parts.Count > 0)
                {
                    for (l = 0; l < methDesc.Body.Parts.Count; l++)
                    {
                        partDesc = methDesc.Body.Parts[l];
                        Console.WriteLine("\t\t\t\t{0}",partDesc.Name);
                    }
                }
            }
        }
    }
}
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.
    Console.WriteLine("Behaviors:")
    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.
    Console.WriteLine("Endpoints")
    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

備註

MessageDescription 包含 HeadersBody 屬性,讓使用者可存取訊息中的這些部分。 Direction 屬性會指出訊息是傳入或傳出訊息, 它也會提供 Action 屬性,其中 URI 會指出訊息的意圖可以指定。

建構函式

MessageDescription(String, MessageDirection)

使用指定的動作和方向,初始化 MessageDescription 類別的新執行個體。

屬性

Action

取得或設定識別訊息目的之 SOAP 訊息的動作參數。

Body

取得 SOAP 訊息的本文。

Direction

取得指出訊息是傳入或傳出訊息的方向。

HasProtectionLevel

取得值,這個值會指出是否已設定 ProtectionLevel

Headers

取得 SOAP 訊息標頭的描述。

MessageType

取得或設定類型,這個類型會識別訊息合約的類型。

Properties

取得 SOAP 訊息屬性的描述。

ProtectionLevel

取得或設定訊息所需要的安全性服務。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ShouldSerializeProtectionLevel()

傳回值,這個值表示 ProtectionLevel 屬性是否已變更為非預設值且應該序列化。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於