MessageContractAttribute 클래스

정의

SOAP 메시지에 해당하는 강력한 형식의 클래스를 정의합니다.

public ref class MessageContractAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct, AllowMultiple=false)]
public sealed class MessageContractAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct)]
public sealed class MessageContractAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct, AllowMultiple=false)>]
type MessageContractAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct)>]
type MessageContractAttribute = class
    inherit Attribute
Public NotInheritable Class MessageContractAttribute
Inherits Attribute
상속
MessageContractAttribute
특성

예제

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

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

설명

MessageContractAttribute 특성을 사용하여 특정 메시지에 대한 SOAP 봉투의 구조를 지정합니다. 그러면 서비스에서 메시지를 매개 변수로 사용하거나 서비스 작업에서 반환 형식으로 사용할 수 있습니다. 기본 SOAP 봉투 자체를 수정하지 않고 SOAP 본문의 콘텐츠 직렬화를 제어하는 방법에 대한 자세한 내용은 서비스 계약에서 데이터 전송 지정데이터 계약 사용을 참조System.Runtime.Serialization.DataContractAttribute하세요.

참고

일반 직렬화 가능 매개 변수를 사용하여 서비스 작업에서 사용자 지정 메시지 형식을 사용할 수 없습니다. 사용자 지정 메시지 형식 또는 개체가 아닌 Message 직렬화 가능한 매개 변수를 사용합니다. 자세한 내용은 서비스 계약에서 데이터 전송 지정을 참조하세요.

형식에 대한 메시지 계약을 구현하려면 형식에 주석 MessageContractAttribute 을 달고 하나 이상의 클래스 필드 또는 속성MessageBodyMemberAttributeMessageHeaderAttributeMessageHeaderArrayAttribute에 주석을 달거나 .

참고

System.ServiceModel.MessageParameterAttribute는 메시지 계약 특성이 아니며 .MessageContractAttribute

ActionReplyAction 속성을 사용하여 SOAP 메시지에서 요소의 <Action> 값을 지정합니다.

  • HasProtectionLevelProtectionLevel 속성을 사용하여 SOAP 메시지 형식에 보호 수준이 있는지 여부와 보호 수준이 있는지 여부를 나타냅니다.

  • IsWrapped 이 속성을 사용하여 메시지 본문에 래퍼 요소가 있는지 여부를 나타내고, 이 경우 및 WrapperNamespace 속성을 사용하여 WrapperName 래핑 요소의 이름과 네임스페이스를 각각 지정합니다.

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

생성자

MessageContractAttribute()

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

속성

HasProtectionLevel

메시지에 보호 수준이 있는지 여부를 나타내는 값을 가져옵니다.

IsWrapped

메시지 본문에 래퍼 요소가 있는지 여부를 지정하는 값을 가져오거나 설정합니다.

ProtectionLevel

메시지 암호화, 서명 또는 두 가지 모두가 필요한지 여부를 지정하는 값을 가져오거나 설정합니다.

TypeId

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

(다음에서 상속됨 Attribute)
WrapperName

메시지 본문의 래퍼 요소 이름을 가져오거나 설정합니다.

WrapperNamespace

메시지 본문 래퍼 요소의 네임스페이스를 가져오거나 설정합니다.

메서드

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)

적용 대상