ServiceKnownTypeAttribute 클래스

정의

직렬화 또는 역직렬화할 때 서비스에서 사용할 알려진 형식을 지정합니다.

public ref class ServiceKnownTypeAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)]
public sealed class ServiceKnownTypeAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)>]
type ServiceKnownTypeAttribute = class
    inherit Attribute
Public NotInheritable Class ServiceKnownTypeAttribute
Inherits Attribute
상속
ServiceKnownTypeAttribute
특성

예제

다음 예제에서는 특성이 메서드 이름과 선언 형식을 지정하는 인터페이스에 특성을 적용 ServiceKnownTypeAttribute 합니다.

// Define a service contract and apply the ServiceKnownTypeAttribute
// to specify types to include when generating client code.
// The types must have the DataContractAttribute and DataMemberAttribute
// applied to be serialized and deserialized. The attribute specifies the
// name of a method (GetKnownTypes) in a class (Helper) defined below.
[ServiceKnownType("GetKnownTypes", typeof(Helper))]
[ServiceContract()]
public interface ICatalog
{
    // Any object type can be inserted into a Hashtable. The
    // ServiceKnownTypeAttribute allows you to include those types
    // with the client code.
    [OperationContract]
    Hashtable GetItems();
}

// This class has the method named GetKnownTypes that returns a generic IEnumerable.
static class Helper
{
    public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider)
    {
        System.Collections.Generic.List<System.Type> knownTypes =
            new System.Collections.Generic.List<System.Type>();
        // Add any types to include here.
        knownTypes.Add(typeof(Widget));
        knownTypes.Add(typeof(Machine));
        return knownTypes;
    }
}

[DataContract()]
public class Widget
{
    [DataMember]
    public string Id;
    [DataMember]
    public string Catalog;
}

[DataContract()]
public class Machine : Widget
{
    [DataMember]
    public string Maker;
}
' Define a service contract and apply the ServiceKnownTypeAttribute
' to specify types to include when generating client code. 
' The types must have the DataContractAttribute and DataMemberAttribute
' applied to be serialized and deserialized. The attribute specifies the 
' name of a method (GetKnownTypes) in a class (Helper) defined below.
<ServiceKnownType("GetKnownTypes", GetType(Helper)), ServiceContract()>  _
Public Interface ICalculator
    ' Any object type can be inserted into a Hashtable. The 
    ' ServiceKnownTypeAttribute allows you to include those types
    ' with the client code.
    <OperationContract()>  _
    Function GetItems() As Hashtable 
End Interface 

' This class has the method named GetKnownTypes that returns a generic IEnumerable.
Friend Class Helper
    Public Shared  Function GetKnownTypes(provider As ICustomAttributeProvider) _
     As IEnumerable(of Type) 
        Dim knownTypes As List(Of Type) = New List(Of Type)
        ' Add any types to include here.
        knownTypes.Add(GetType(Widget))
        knownTypes.Add(GetType(Machine))
        Return knownTypes
    End Function 
End Class 

<DataContract()>  _
Public Class Widget
    <DataMember()>  _
    Public Id As String
    <DataMember()>  _
    Public Catalog As String
End Class 

<DataContract()>  _
Public Class Machine
    Inherits Widget
    <DataMember()>  _
    Public Maker As String
End Class

또는 포함할 알려진 형식을 지정하는 인터페이스에 특성을 적용합니다.

// Apply the ServiceKnownTypeAttribute to the
// interface specifying the type to include. Apply
// the attribute more than once if needed.
[ServiceKnownType(typeof(Widget))]
[ServiceKnownType(typeof(Machine))]
[ServiceContract()]
public interface ICatalog2
{
    // Any object type can be inserted into a Hashtable. The
    // ServiceKnownTypeAttribute allows you to include those types
    // with the client code.
    [OperationContract]
    Hashtable GetItems();
}
' Apply the ServiceKnownTypeAttribute to the 
' interface specifying the type to include. Apply the attribute
' more than once, if needed.
<ServiceKnownType(GetType(Widget)), ServiceKnownType(GetType(Machine)), _
 ServiceContract()>  _
Public Interface ICalculator2
    ' Any object type can be inserted into a Hashtable. The 
    ' ServiceKnownTypeAttribute allows you to include those types
    ' with the client code.
    <OperationContract()>  _
    Function GetItems() As Hashtable 
End Interface

설명

ServiceKnownTypeAttribute WCF(Windows Communication Foundation) 서비스 계약(서비스 및 해당 메서드를 정의하는 인터페이스)을 만들 때 사용하기 위한 것입니다. 알려진 형식 은 serialization 또는 deserialization이 발생할 때 개체 그래프에 있을 수 있는 형식입니다. 알려진된 형식에 대 한 자세한 내용은 참조 하세요. 데이터 계약 알려진 형식을합니다.

속성을 사용 MethodName 하려면 형식 배열(각각 알려진 형식)을 반환하는 메서드(또는 메서드)가 포함된 클래스를 만듭니다. 특성을 methodName 적용할 때 형식 목록을 반환하는 메서드의 이름으로 설정하고 메서드를 포함하는 형식으로 설정합니다 declaringType . 메서드는 인터페이스를 구현하는 형식을 IEnumerable<T> 반환해야 합니다. 메서드에는 형식 ICustomAttributeProvider의 매개 변수도 포함되어야 합니다.

새 알려진 형식을 지정할 때마다 인터페이스, 클래스 또는 메서드에 특성을 여러 번 적용할 수도 있습니다.

참고

Microsoft Visual Basic 또는 C# 코드에서 더 긴 ServiceKnownTypeAttribute단어 대신 사용할 ServiceKnownType 수 있습니다.

생성자

ServiceKnownTypeAttribute(String)

ServiceKnownTypeAttribute 클래스의 새 인스턴스를 초기화하고 알려진 형식을 반환하는 메서드 이름을 지정합니다.

ServiceKnownTypeAttribute(String, Type)

알려진 형식을 반환하는 메서드의 이름과 알려진 형식을 반환하는 하나 이상의 메서드가 포함된 형식을 사용하여 ServiceKnownTypeAttribute 클래스의 새 인스턴스를 초기화합니다.

ServiceKnownTypeAttribute(Type)

지정된 알려진 형식을 사용하여 ServiceKnownTypeAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

DeclaringType

알려진 형식을 반환하는 메서드가 포함된 형식을 가져옵니다.

MethodName

알려진 형식의 컬렉션을 반환하는 메서드의 이름을 가져옵니다.

Type

개체 그래프에 포함할 수 있는 알려진 형식입니다.

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)

적용 대상

추가 정보