MessageHeaderAttribute 클래스

정의

데이터 멤버가 SOAP 메시지 헤더임을 지정합니다.

public ref class MessageHeaderAttribute : System::ServiceModel::MessageContractMemberAttribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)]
public class MessageHeaderAttribute : System.ServiceModel.MessageContractMemberAttribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=false)>]
type MessageHeaderAttribute = class
    inherit MessageContractMemberAttribute
Public Class MessageHeaderAttribute
Inherits MessageContractMemberAttribute
상속
파생
특성

예제

다음 코드 예제를 사용 하 여 MessageHeaderAttribute 응답 메시지에 NameNamespace 대 한 SOAP 헤더를 만드는 합니다 및 MustUnderstand 속성이이 헤더에 대 한 적절 한 값으로 설정 합니다. 코드 예제 뒤에 메시지의 예제가 전송됩니다.

 [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 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

설명

MessageHeaderAttribute 특성을 사용하면 특성으로 표시된 MessageContractAttribute 형식의 필드와 속성을 SOAP 메시지 헤더에 매핑할 수 있습니다. 필드 또는 속성은 직렬화할 수 있는 단순 형식 또는 복합 형식일 수 있습니다.

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

메시지 계약을 만드는 방법에 대한 자세한 내용은 메시지 계약 사용을 참조하세요.

SOAP 표준은 헤더에 존재할 수 있는 다음 특성을 정의합니다.

  • Actor 또는 Role (Actor SOAP 1.1의 경우 SOAP Role 1.2)

  • MustUnderstand

  • Relay

또는 Role 특성은 Actor 지정된 헤더가 의도된 노드의 URI를 지정합니다. 특성은 MustUnderstand 헤더가 노드 처리를 이해하는지 여부를 지정합니다. Relay 특성은 헤더를 다운스트림 노드로 릴레이할지 여부를 지정합니다. WCF(Windows Communication Foundation)는 들어오는 메시지에서 이러한 특성을 처리하지 않습니다( 특성 제외) MustUnderstand .

그러나 이러한 특성은 기본적으로 전송되지 않더라도 읽고 쓸 수 있습니다. 특성 값을 두 가지 방법으로 설정할 수 있습니다. 먼저 에서 , MustUnderstandRelay 속성을 MessageHeaderAttribute변경할 Actor수 있습니다. (속성이 없습니다Role. 속성을 Role 설정하고 Actor SOAP 1.2를 사용하는 경우 전달됨). 예를 들면 다음과 같습니다.

이러한 특성을 제어하는 두 번째 방법은 원하는 헤더 형식을 클래스의 MessageHeader<T> 형식 매개 변수로 만들고 결과 형식을 와 함께 MessageHeaderAttribute사용하는 것입니다. 그런 다음, 속성을 프로그래밍 방식으로 사용하여 MessageHeader<T> SOAP 특성을 설정합니다. 예를 들면 다음과 같습니다.

동적 및 정적 제어 메커니즘을 모두 사용하는 경우 정적 설정은 기본값이지만 동적 메커니즘을 사용하여 재정의할 수 있습니다. 예를 들면 다음과 같습니다.

동적 특성 컨트롤을 사용하여 반복되는 헤더를 만들 수 있습니다. 예를 들면 다음과 같습니다.

[MessageHeaderArray] public MessageHeader<Person> documentApprovers[];  

수신 쪽에서 이러한 SOAP 특성을 읽는 것은 제네릭 MessageHeader<T> 클래스를 사용하는 경우에만 수행할 수 있습니다. 형식의 Actor헤더 MessageHeader<T> 의 또는 RelayMustUnderstand 속성을 검사하여 수신된 메시지에서 특성 설정을 검색합니다.

메시지를 받은 다음 다시 보내면 SOAP 특성 설정은 형식의 MessageHeader<T> 헤더에 대해서만 왕복합니다.

생성자

MessageHeaderAttribute()

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

속성

Actor

이 헤더의 대상이 되는 노드를 나타내는 URI를 가져오거나 설정합니다. SOAP 1.2를 사용하는 경우에는 역할 헤더 특성에 매핑하고, SOAP 1.1을 사용하는 경우에는 행위자 헤더 특성에 매핑합니다.

HasProtectionLevel

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

(다음에서 상속됨 MessageContractMemberAttribute)
MustUnderstand

Actor 역할에서 동작하는 노드가 이 헤더를 인식해야 하는지 여부를 지정합니다. 이 설정은 mustUnderstand SOAP 헤더 특성에 매핑됩니다.

Name

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

(다음에서 상속됨 MessageContractMemberAttribute)
Namespace

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

(다음에서 상속됨 MessageContractMemberAttribute)
ProtectionLevel

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

(다음에서 상속됨 MessageContractMemberAttribute)
Relay

이 헤더를 다운스트림 노드로 릴레이할지 여부를 지정합니다. 이 설정은 relay SOAP 헤더 특성에 매핑됩니다.

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)

적용 대상