ServiceKnownTypeAttribute Constructeurs
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la classe ServiceKnownTypeAttribute.
Surcharges
| Nom | Description |
|---|---|
| ServiceKnownTypeAttribute(String) |
Initialise une nouvelle instance de la ServiceKnownTypeAttribute classe et spécifie le nom d’une méthode qui retourne les types connus. |
| ServiceKnownTypeAttribute(Type) |
Initialise une nouvelle instance de la ServiceKnownTypeAttribute classe avec le type connu spécifié. |
| ServiceKnownTypeAttribute(String, Type) |
Initialise une nouvelle instance de la ServiceKnownTypeAttribute classe avec le nom d’une méthode qui retourne les types connus et le type qui contient la méthode (ou les méthodes) qui retourne les types connus. |
ServiceKnownTypeAttribute(String)
- Source:
- ServiceKnownTypeAttribute.cs
- Source:
- ServiceKnownTypeAttribute.cs
- Source:
- ServiceKnownTypeAttribute.cs
Initialise une nouvelle instance de la ServiceKnownTypeAttribute classe et spécifie le nom d’une méthode qui retourne les types connus.
public:
ServiceKnownTypeAttribute(System::String ^ methodName);
public ServiceKnownTypeAttribute(string methodName);
new System.ServiceModel.ServiceKnownTypeAttribute : string -> System.ServiceModel.ServiceKnownTypeAttribute
Public Sub New (methodName As String)
Paramètres
- methodName
- String
Nom d’une méthode qui retourne les types connus.
Remarques
Utilisez ce constructeur lors de l’application ServiceKnownTypeAttribute à une classe qui contient des méthodes qui retournent des types connus.
Voir aussi
S’applique à
ServiceKnownTypeAttribute(Type)
- Source:
- ServiceKnownTypeAttribute.cs
- Source:
- ServiceKnownTypeAttribute.cs
- Source:
- ServiceKnownTypeAttribute.cs
Initialise une nouvelle instance de la ServiceKnownTypeAttribute classe avec le type connu spécifié.
public:
ServiceKnownTypeAttribute(Type ^ type);
public ServiceKnownTypeAttribute(Type type);
new System.ServiceModel.ServiceKnownTypeAttribute : Type -> System.ServiceModel.ServiceKnownTypeAttribute
Public Sub New (type As Type)
Paramètres
- type
- Type
Spécifie un type connu qui peut être utilisé dans un paramètre ou une valeur de retour définie par le service.
Exemples
L’exemple suivant applique l’attribut ServiceKnownTypeAttribute à une interface où l’attribut spécifie le type à inclure.
// 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
Remarques
L’application ServiceKnownTypeAttribute peut être appliquée plusieurs fois à une méthode, chaque application nommant un type connu différent qui peut être présent dans le graphique d’objet retourné par la méthode.
S’applique à
ServiceKnownTypeAttribute(String, Type)
- Source:
- ServiceKnownTypeAttribute.cs
- Source:
- ServiceKnownTypeAttribute.cs
- Source:
- ServiceKnownTypeAttribute.cs
Initialise une nouvelle instance de la ServiceKnownTypeAttribute classe avec le nom d’une méthode qui retourne les types connus et le type qui contient la méthode (ou les méthodes) qui retourne les types connus.
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)
Paramètres
- methodName
- String
Nom d’une méthode qui retourne les types connus.
- declaringType
- Type
Type qui peut utiliser les types connus dans son graphique d’objets.
Exemples
L’exemple suivant applique l’attribut ServiceKnownTypeAttribute à une interface où l’attribut spécifie un nom de méthode et un type déclarant.
// 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