MessageBodyMemberAttribute Klasa

Definicja

Określa, że element członkowski jest serializowany jako element wewnątrz treści protokołu SOAP.

public ref class MessageBodyMemberAttribute : System::ServiceModel::MessageContractMemberAttribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, Inherited=false)]
public class MessageBodyMemberAttribute : System.ServiceModel.MessageContractMemberAttribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, Inherited=false)>]
type MessageBodyMemberAttribute = class
    inherit MessageContractMemberAttribute
Public Class MessageBodyMemberAttribute
Inherits MessageContractMemberAttribute
Dziedziczenie
MessageBodyMemberAttribute
Atrybuty

Przykłady

W poniższym przykładzie kodu przedstawiono użycie MessageContractAttribute elementu do sterowania strukturą kopert protokołu SOAP zarówno dla komunikatu żądania, jak i komunikatu odpowiedzi, oraz użycie zarówno MessageHeaderAttribute nagłówka PROTOKOŁU SOAP dla komunikatu odpowiedzi, MessageBodyMemberAttribute jak i (w celu określenia treści zarówno żądania, jak i komunikatu odpowiedzi). Przykładowy kod zawiera przykład każdego komunikatu po wysłaniu.

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(Namespace = "Microsoft.WCF.Documentation")]
  interface IMessagingHello
  {
    [OperationContract(
     Action = "http://GreetingMessage/Action",
     ReplyAction = "http://HelloResponseMessage/Action"
    )]
    HelloResponseMessage Hello(HelloGreetingMessage msg);
  }

  [MessageContract]
  public class HelloResponseMessage
  {
    private string localResponse = String.Empty;
    private string extra = String.Empty;

    [MessageBodyMember(
      Name = "ResponseToGreeting",
      Namespace = "http://www.examples.com")]
    public string Response
    {
      get { return localResponse; }
      set { localResponse = value; }
    }

    [MessageHeader(
      Name = "OutOfBandData",
      Namespace = "http://www.examples.com",
      MustUnderstand=true
    )]
    public string ExtraValues
    {
      get { return extra; }
      set { this.extra = value; }
   }

   /*
    The following is the response message, edited for clarity.

    <s:Envelope>
      <s:Header>
        <a:Action s:mustUnderstand="1">http://HelloResponseMessage/Action</a:Action>
        <h:OutOfBandData s:mustUnderstand="1" xmlns:h="http://www.examples.com">Served by object 13804354.</h:OutOfBandData>
      </s:Header>
      <s:Body>
        <HelloResponseMessage xmlns="Microsoft.WCF.Documentation">
          <ResponseToGreeting xmlns="http://www.examples.com">Service received: Hello.</ResponseToGreeting>
        </HelloResponseMessage>
      </s:Body>
    </s:Envelope>
    */
 }
  [MessageContract]
  public class HelloGreetingMessage
  {
    private string localGreeting;

    [MessageBodyMember(
      Name = "Salutations",
      Namespace = "http://www.examples.com"
    )]
    public string Greeting
    {
      get { return localGreeting; }
      set { localGreeting = value; }
    }
  }

  /*
   The following is the request message, edited for clarity.

    <s:Envelope>
      <s:Header>
        <!-- Note: Some header content has been removed for clarity.
        <a:Action>http://GreetingMessage/Action</a:Action>
        <a:To s:mustUnderstand="1"></a:To>
      </s:Header>
      <s:Body u:Id="_0" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <HelloGreetingMessage xmlns="Microsoft.WCF.Documentation">
          <Salutations xmlns="http://www.examples.com">Hello.</Salutations>
        </HelloGreetingMessage>
      </s:Body>
   </s:Envelope>
   */

  class MessagingHello : IMessagingHello
  {
    public HelloResponseMessage Hello(HelloGreetingMessage msg)
    {
      Console.WriteLine("Caller sent: " + msg.Greeting);
      HelloResponseMessage responseMsg = new HelloResponseMessage();
      responseMsg.Response = "Service received: " + msg.Greeting;
      responseMsg.ExtraValues = String.Format("Served by object {0}.", this.GetHashCode().ToString());
      Console.WriteLine("Returned response message.");
      return responseMsg;
    }
  }
}
Imports System.Runtime.Serialization
Imports System.ServiceModel
Imports System.ServiceModel.Channels

Namespace Microsoft.WCF.Documentation
  <ServiceContract(Namespace := "Microsoft.WCF.Documentation")> _
  Friend Interface IMessagingHello
    <OperationContract(Action := "http://GreetingMessage/Action", ReplyAction := "http://HelloResponseMessage/Action")> _
    Function Hello(ByVal msg As HelloGreetingMessage) As HelloResponseMessage
  End Interface

  <MessageContract> _
  Public Class HelloResponseMessage
    Private localResponse As String = String.Empty
    Private extra As String = String.Empty

    <MessageBodyMember(Name := "ResponseToGreeting", Namespace := "http://www.examples.com")> _
    Public Property Response() As String
      Get
          Return localResponse
      End Get
      Set(ByVal value As String)
          localResponse = value
      End Set
    End Property

    <MessageHeader(Name := "OutOfBandData", Namespace := "http://www.examples.com", MustUnderstand:=True)> _
    Public Property ExtraValues() As String
      Get
          Return extra
      End Get
      Set(ByVal value As String)
          Me.extra = value
      End Set
    End Property

'   
'    The following is the response message, edited for clarity.
'    
'    <s:Envelope>
'      <s:Header>
'        <a:Action s:mustUnderstand="1">http://HelloResponseMessage/Action</a:Action>
'        <h:OutOfBandData s:mustUnderstand="1" xmlns:h="http://www.examples.com">Served by object 13804354.</h:OutOfBandData>
'      </s:Header>
'      <s:Body>
'        <HelloResponseMessage xmlns="Microsoft.WCF.Documentation">
'          <ResponseToGreeting xmlns="http://www.examples.com">Service received: Hello.</ResponseToGreeting>
'      </s:Body>    
'    </s:Envelope>
'    
  End Class
  <MessageContract> _
  Public Class HelloGreetingMessage
    Private localGreeting As String

    <MessageBodyMember(Name := "Salutations", Namespace := "http://www.examples.com")> _
    Public Property Greeting() As String
      Get
          Return localGreeting
      End Get
      Set(ByVal value As String)
          localGreeting = value
      End Set
    End Property
  End Class

'  
'   The following is the request message, edited for clarity.
'    
'    <s:Envelope>
'      <s:Header>
'        <!-- Note: Some header content has been removed for clarity.
'        <a:Action>http://GreetingMessage/Action</a:Action> 
'        <a:To s:mustUnderstand="1"></a:To>
'      </s:Header>
'      <s:Body u:Id="_0" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
'        <HelloGreetingMessage xmlns="Microsoft.WCF.Documentation">
'          <Salutations xmlns="http://www.examples.com">Hello.</Salutations>
'      </s:Body>
'   </s:Envelope>
'   

  Friend Class MessagingHello
      Implements IMessagingHello
    Public Function Hello(ByVal msg As HelloGreetingMessage) As HelloResponseMessage Implements IMessagingHello.Hello
      Console.WriteLine("Caller sent: " & msg.Greeting)
      Dim responseMsg As New HelloResponseMessage()
      responseMsg.Response = "Service received: " & msg.Greeting
      responseMsg.ExtraValues = String.Format("Served by object {0}.", Me.GetHashCode().ToString())
      Console.WriteLine("Returned response message.")
      Return responseMsg
    End Function
  End Class
End Namespace

Uwagi

Użyj atrybutu MessageBodyMemberAttribute , aby określić, że element członkowski danych jest serializowany w treści protokołu SOAP i kontrolować niektóre elementy serializacji.

Właściwość Order służy do określania kolejności części ciała w przypadkach, gdy domyślna kolejność alfabetyczna nie jest odpowiednia.

Pozostałe właściwości są dziedziczone z klasy bazowej . System.ServiceModel.MessageContractMemberAttribute

Aby uzyskać więcej informacji na temat kontrolowania serializacji zawartości treści protokołu SOAP bez modyfikowania domyślnej koperty protokołu SOAP, zobacz System.Runtime.Serialization.DataContractAttribute, Określanie transferu danych w kontraktach usług i Używanie kontraktów danych.

Aby uzyskać więcej informacji, zobacz Using Message Contracts (Używanie kontraktów komunikatów).

Konstruktory

MessageBodyMemberAttribute()

Inicjuje nowe wystąpienie klasy MessageBodyMemberAttribute.

Właściwości

HasProtectionLevel

Po przesłonięciu w klasie pochodnej pobiera wartość wskazującą, czy element członkowski ma przypisany poziom ochrony.

(Odziedziczone po MessageContractMemberAttribute)
Name

Określa nazwę elementu odpowiadającego temu elementowi członkowskiemu.

(Odziedziczone po MessageContractMemberAttribute)
Namespace

Określa przestrzeń nazw elementu, który odpowiada temu składowi.

(Odziedziczone po MessageContractMemberAttribute)
Order

Pobiera lub ustawia wartość wskazującą położenie, w którym element członkowski jest serializowany w treści protokołu SOAP.

ProtectionLevel

Określa, czy element członkowski ma być przesyłany jako, podpisany, czy podpisany i zaszyfrowany.

(Odziedziczone po MessageContractMemberAttribute)
TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego elementu Attribute.

(Odziedziczone po Attribute)

Metody

Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi.

(Odziedziczone po Attribute)
GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

(Odziedziczone po Attribute)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
IsDefaultAttribute()

W przypadku zastąpienia w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

W przypadku zastąpienia w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie obiektu, którego można użyć do pobrania informacji o typie interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy