ServiceKnownTypeAttribute Constructors
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Initialiseert een nieuw exemplaar van de ServiceKnownTypeAttribute klasse.
Overloads
| Name | Description |
|---|---|
| ServiceKnownTypeAttribute(String) |
Initialiseert een nieuw exemplaar van de ServiceKnownTypeAttribute klasse en geeft de naam op van een methode die de bekende typen retourneert. |
| ServiceKnownTypeAttribute(Type) |
Initialiseert een nieuw exemplaar van de ServiceKnownTypeAttribute klasse met het opgegeven bekende type. |
| ServiceKnownTypeAttribute(String, Type) |
Initialiseert een nieuw exemplaar van de ServiceKnownTypeAttribute klasse met de naam van een methode die de bekende typen retourneert en het type dat de methode (of methoden) bevat die de bekende typen retourneert. |
ServiceKnownTypeAttribute(String)
Initialiseert een nieuw exemplaar van de ServiceKnownTypeAttribute klasse en geeft de naam op van een methode die de bekende typen retourneert.
public:
ServiceKnownTypeAttribute(System::String ^ methodName);
public ServiceKnownTypeAttribute(string methodName);
new System.ServiceModel.ServiceKnownTypeAttribute : string -> System.ServiceModel.ServiceKnownTypeAttribute
Public Sub New (methodName As String)
Parameters
- methodName
- String
De naam van een methode die de bekende typen retourneert.
Opmerkingen
Gebruik deze constructor bij het toepassen van de ServiceKnownTypeAttribute op een klasse die methoden bevat die bekende typen retourneren.
Zie ook
Van toepassing op
ServiceKnownTypeAttribute(Type)
Initialiseert een nieuw exemplaar van de ServiceKnownTypeAttribute klasse met het opgegeven bekende type.
public:
ServiceKnownTypeAttribute(Type ^ type);
public ServiceKnownTypeAttribute(Type type);
new System.ServiceModel.ServiceKnownTypeAttribute : Type -> System.ServiceModel.ServiceKnownTypeAttribute
Public Sub New (type As Type)
Parameters
- type
- Type
Hiermee geeft u een bekend type op dat kan worden gebruikt in een parameter of retourwaarde die is gedefinieerd door de service.
Voorbeelden
In het volgende voorbeeld wordt het ServiceKnownTypeAttribute kenmerk toegepast op een interface waarin het kenmerk het type specificeert dat moet worden opgenomen.
// 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
Opmerkingen
De ServiceKnownTypeAttribute kan meerdere keren worden toegepast op een methode, waarbij elke toepassing een ander bekend type noemt dat mogelijk aanwezig is in de objectgrafiek die door de methode wordt geretourneerd.
Van toepassing op
ServiceKnownTypeAttribute(String, Type)
Initialiseert een nieuw exemplaar van de ServiceKnownTypeAttribute klasse met de naam van een methode die de bekende typen retourneert en het type dat de methode (of methoden) bevat die de bekende typen retourneert.
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)
Parameters
- methodName
- String
De naam van een methode die de bekende typen retourneert.
- declaringType
- Type
Het type dat de bekende typen in de objectgrafiek kan gebruiken.
Voorbeelden
In het volgende voorbeeld wordt het ServiceKnownTypeAttribute kenmerk toegepast op een interface waarin het kenmerk een methodenaam en een declarerend type opgeeft.
// 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