ServiceKnownTypeAttribute 생성자

정의

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

오버로드

ServiceKnownTypeAttribute(String)

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

ServiceKnownTypeAttribute(Type)

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

ServiceKnownTypeAttribute(String, Type)

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

ServiceKnownTypeAttribute(String)

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

public:
 ServiceKnownTypeAttribute(System::String ^ methodName);
public ServiceKnownTypeAttribute (string methodName);
new System.ServiceModel.ServiceKnownTypeAttribute : string -> System.ServiceModel.ServiceKnownTypeAttribute
Public Sub New (methodName As String)

매개 변수

methodName
String

알려진 형식을 반환하는 메서드의 이름입니다.

설명

알려진 형식을 반환하는 ServiceKnownTypeAttribute 메서드가 포함된 클래스에 적용할 때 이 생성자를 사용합니다.

추가 정보

적용 대상

ServiceKnownTypeAttribute(Type)

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

public:
 ServiceKnownTypeAttribute(Type ^ type);
public ServiceKnownTypeAttribute (Type type);
new System.ServiceModel.ServiceKnownTypeAttribute : Type -> System.ServiceModel.ServiceKnownTypeAttribute
Public Sub New (type As Type)

매개 변수

type
Type

서비스에서 정의한 매개 변수 또는 반환 값에서 사용할 수 있는 알려진 형식을 지정합니다.

예제

다음 예제에서는 특성이 ServiceKnownTypeAttribute 포함할 형식을 지정하는 인터페이스에 특성을 적용합니다.

// 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를 메서드에 여러 번 적용할 수 있습니다.

적용 대상

ServiceKnownTypeAttribute(String, Type)

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

public:
 ServiceKnownTypeAttribute(System::String ^ methodName, Type ^ declaringType);
public ServiceKnownTypeAttribute (string methodName, Type declaringType);
new System.ServiceModel.ServiceKnownTypeAttribute : string * Type -> System.ServiceModel.ServiceKnownTypeAttribute
Public Sub New (methodName As String, declaringType As Type)

매개 변수

methodName
String

알려진 형식을 반환하는 메서드의 이름입니다.

declaringType
Type

개체 그래프에서 알려진 형식을 사용할 수 있는 형식입니다.

예제

다음 예제에서는 특성이 메서드 이름과 선언 형식을 지정하는 인터페이스에 특성을 적용 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

추가 정보

적용 대상