ServiceKnownTypeAttribute Konstruktory

Definice

Inicializuje novou instanci ServiceKnownTypeAttribute třídy .

Přetížení

ServiceKnownTypeAttribute(String)

Inicializuje novou instanci ServiceKnownTypeAttribute třídy a určuje název metody, která vrací známé typy.

ServiceKnownTypeAttribute(Type)

Inicializuje novou instanci ServiceKnownTypeAttribute třídy se zadaným známým typem.

ServiceKnownTypeAttribute(String, Type)

Inicializuje novou instanci ServiceKnownTypeAttribute třídy s názvem metody, která vrací známé typy a typ, který obsahuje metodu (nebo metody), která vrací známé typy.

ServiceKnownTypeAttribute(String)

Zdroj:
ServiceKnownTypeAttribute.cs
Zdroj:
ServiceKnownTypeAttribute.cs
Zdroj:
ServiceKnownTypeAttribute.cs

Inicializuje novou instanci ServiceKnownTypeAttribute třídy a určuje název metody, která vrací známé typy.

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

Parametry

methodName
String

Název metody, která vrací známé typy.

Poznámky

Tento konstruktor použijte při použití ServiceKnownTypeAttribute na třídu, která obsahuje metody, které vracejí známé typy.

Viz také

Platí pro

ServiceKnownTypeAttribute(Type)

Zdroj:
ServiceKnownTypeAttribute.cs
Zdroj:
ServiceKnownTypeAttribute.cs
Zdroj:
ServiceKnownTypeAttribute.cs

Inicializuje novou instanci ServiceKnownTypeAttribute třídy se zadaným známým typem.

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

Parametry

type
Type

Určuje známý typ, který lze použít v parametru nebo návratové hodnotě definované službou.

Příklady

Následující příklad aplikuje ServiceKnownTypeAttribute atribut na rozhraní, kde atribut určuje typ, který se má zahrnout.

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

Poznámky

Metodu ServiceKnownTypeAttribute lze použít několikrát, přičemž každá aplikace pojmovává jiný známý typ, který může být přítomen v grafu objektu vráceného metodou.

Platí pro

ServiceKnownTypeAttribute(String, Type)

Zdroj:
ServiceKnownTypeAttribute.cs
Zdroj:
ServiceKnownTypeAttribute.cs
Zdroj:
ServiceKnownTypeAttribute.cs

Inicializuje novou instanci ServiceKnownTypeAttribute třídy s názvem metody, která vrací známé typy a typ, který obsahuje metodu (nebo metody), která vrací známé typy.

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)

Parametry

methodName
String

Název metody, která vrací známé typy.

declaringType
Type

Typ, který může použít známé typy v grafu objektů.

Příklady

Následující příklad použije ServiceKnownTypeAttribute atribut na rozhraní, kde atribut určuje název metody a deklarující typ.

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

Viz také

Platí pro