ServiceKnownTypeAttribute Конструкторы

Определение

Инициализирует новый экземпляр класса ServiceKnownTypeAttribute.

Перегрузки

ServiceKnownTypeAttribute(String)

Инициализирует новый экземпляр класса ServiceKnownTypeAttribute и задает имя метода, который возвращает известные типы.

ServiceKnownTypeAttribute(Type)

Инициализирует новый экземпляр класса ServiceKnownTypeAttribute с заданным известным типом.

ServiceKnownTypeAttribute(String, Type)

Инициализирует новый экземпляр класса ServiceKnownTypeAttribute с именем метода, который возвращает известные типы и тип, содержащий метод (или методы), возвращающий известные типы.

ServiceKnownTypeAttribute(String)

Исходный код:
ServiceKnownTypeAttribute.cs
Исходный код:
ServiceKnownTypeAttribute.cs
Исходный код:
ServiceKnownTypeAttribute.cs

Инициализирует новый экземпляр класса 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.cs
Исходный код:
ServiceKnownTypeAttribute.cs
Исходный код:
ServiceKnownTypeAttribute.cs

Инициализирует новый экземпляр класса 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.cs
Исходный код:
ServiceKnownTypeAttribute.cs
Исходный код:
ServiceKnownTypeAttribute.cs

Инициализирует новый экземпляр класса 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

См. также раздел

Применяется к