MessageBodyMemberAttribute 클래스

정의

멤버가 SOAP 본문 내의 요소로 serialize되도록 지정합니다.

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
상속
MessageBodyMemberAttribute
특성

예제

다음 코드 예제에서는 MessageContractAttribute 요청 메시지와 응답 메시지 둘 다에 대 한 SOAP 봉투 구조를 제어 하는 사용 및 둘 다 MessageHeaderAttribute 의 사용 (응답 메시지에 대 한 SOAP 헤더를 만들기 위해) 및 MessageBodyMemberAttribute (요청 및 응답 메시지의 본문을 지정). 코드 예제에는 전송 시 각 메시지의 예제가 포함되어 있습니다.

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

설명

MessageBodyMemberAttribute 이 특성을 사용하여 데이터 멤버가 SOAP 본문으로 직렬화되도록 지정하고 일부 serialization 항목을 제어합니다.

Order 속성은 기본 사전순 순서가 적절하지 않은 경우 본문 부분의 순서를 지정하는 데 사용됩니다.

다른 속성은 기본 클래스 System.ServiceModel.MessageContractMemberAttribute에서 상속됩니다.

기본 SOAP 봉투 자체를 수정하지 않고 SOAP 본문의 콘텐츠 직렬화를 제어하는 방법에 대한 자세한 내용은 서비스 계약에서 데이터 전송 지정데이터 계약 사용을 참조System.Runtime.Serialization.DataContractAttribute하세요.

자세한 내용은 메시지 계약 사용을 참조하세요.

생성자

MessageBodyMemberAttribute()

MessageBodyMemberAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

HasProtectionLevel

파생 클래스에서 재정의되면 멤버에 할당된 보호 수준이 있는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 MessageContractMemberAttribute)
Name

이 멤버에 해당하는 요소의 이름을 지정합니다.

(다음에서 상속됨 MessageContractMemberAttribute)
Namespace

이 멤버에 해당하는 요소의 네임스페이스를 지정합니다.

(다음에서 상속됨 MessageContractMemberAttribute)
Order

멤버가 serialize되는 SOAP 본문 내의 위치를 나타내는 값을 가져오거나 설정합니다.

ProtectionLevel

멤버를 현재 상태로 전송할지, 서명한 상태로 전송할지, 서명하고 암호화한 상태로 전송할지를 지정합니다.

(다음에서 상속됨 MessageContractMemberAttribute)
TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

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

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상