DataContractSerializerOperationBehavior Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents the run-time behavior of the DataContractSerializer.
public ref class DataContractSerializerOperationBehavior : System::ServiceModel::Description::IOperationBehavior
public ref class DataContractSerializerOperationBehavior : System::ServiceModel::Description::IOperationBehavior, System::ServiceModel::Description::IWsdlExportExtension
public class DataContractSerializerOperationBehavior : System.ServiceModel.Description.IOperationBehavior
public class DataContractSerializerOperationBehavior : System.ServiceModel.Description.IOperationBehavior, System.ServiceModel.Description.IWsdlExportExtension
type DataContractSerializerOperationBehavior = class
interface IOperationBehavior
type DataContractSerializerOperationBehavior = class
interface IOperationBehavior
interface IWsdlExportExtension
Public Class DataContractSerializerOperationBehavior
Implements IOperationBehavior
Public Class DataContractSerializerOperationBehavior
Implements IOperationBehavior, IWsdlExportExtension
- Inheritance
-
DataContractSerializerOperationBehavior
- Implements
The following example finds the DataContractSerializerOperationBehavior in the collection of behaviors for an operation and resets the MaxItemsInObjectGraph and IgnoreExtensionDataObject properties.
private void DataContractBehavior()
{
WSHttpBinding b = new WSHttpBinding(SecurityMode.Message);
Uri baseAddress = new Uri("http://localhost:1066/calculator");
ServiceHost sh = new ServiceHost(typeof(Calculator), baseAddress);
sh.AddServiceEndpoint(typeof(ICalculator), b, "");
// Find the ContractDescription of the operation to find.
ContractDescription cd = sh.Description.Endpoints[0].Contract;
OperationDescription myOperationDescription = cd.Operations.Find("Add");
// Find the serializer behavior.
DataContractSerializerOperationBehavior serializerBehavior =
myOperationDescription.Behaviors.
Find<DataContractSerializerOperationBehavior>();
// If the serializer is not found, create one and add it.
if (serializerBehavior == null)
{
serializerBehavior = new DataContractSerializerOperationBehavior(myOperationDescription);
myOperationDescription.Behaviors.Add(serializerBehavior);
}
// Change the settings of the behavior.
serializerBehavior.MaxItemsInObjectGraph = 10000;
serializerBehavior.IgnoreExtensionDataObject = true;
sh.Open();
Console.WriteLine("Listening");
Console.ReadLine();
}
Private Sub DataContractBehavior()
Dim b As New WSHttpBinding(SecurityMode.Message)
Dim baseAddress As New Uri("http://localhost:1066/calculator")
Dim sh As New ServiceHost(GetType(Calculator), baseAddress)
sh.AddServiceEndpoint(GetType(ICalculator), b, "")
' Find the ContractDescription of the operation to find.
Dim cd As ContractDescription = sh.Description.Endpoints(0).Contract
Dim myOperationDescription As OperationDescription = cd.Operations.Find("Add")
' Find the serializer behavior.
Dim serializerBehavior As DataContractSerializerOperationBehavior = _
myOperationDescription.Behaviors.Find _
(Of DataContractSerializerOperationBehavior)()
' If the serializer is not found, create one and add it.
If serializerBehavior Is Nothing Then
serializerBehavior = New DataContractSerializerOperationBehavior(myOperationDescription)
myOperationDescription.Behaviors.Add(serializerBehavior)
End If
' Change settings of the behavior.
serializerBehavior.MaxItemsInObjectGraph = 10000
serializerBehavior.IgnoreExtensionDataObject = True
sh.Open()
Console.WriteLine("Listening")
Console.ReadLine()
End Sub
The DataContractSerializerOperationBehavior enables the control of DataContractSerializer options, such as the MaxItemsInObjectGraph and IgnoreExtensionDataObject properties. Some of these properties can be set only using the constructor of the class. In that case, the DataContractSerializer can be replaced using the CreateSerializer method. For more information about data contracts, see Using Data Contracts.
For more information about using the DataContractSerializerOperationBehavior to replace the IDataContractSurrogate returned by the DataContractSurrogate property, see Data Contract Surrogates.
Data |
Initializes a new instance of the DataContractSerializerOperationBehavior class with the specified operation description and data contract format. |
Data |
Initializes a new instance of the DataContractSerializerOperationBehavior class with the specified operation description. |
Data |
Gets the DataContractFormatAttribute associated with the operation. |
Data |
Gets or sets an implementation of the DataContractResolver that is used to dynamically map types during serialization and deserialization processes. |
Data |
Gets or sets a surrogate to be used during the serialization and deserialization processes. |
Ignore |
Gets or sets a value that specifies whether the data provided by an extension of a type (and therefore not in the data contract) is ignored or not. |
Max |
Gets or sets the maximum number of items in the object graph to serialize or deserialize. |
Serialization |
Gets or sets a surrogate provider to be used during the serialization and deserialization processes. |
Create |
Creates an instance of a class that inherits from XmlObjectSerializer for serialization and deserialization processes. |
Create |
Creates an instance of a class that inherits from XmlObjectSerializer for serialization and deserialization processes with an XmlDictionaryString that contains the namespace. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
IOperation |
Adds a collection of parameters to the behavior. |
IOperation |
Attaches a client behavior to the operation. |
IOperation |
Applies the behavior to the operation. |
IOperation |
Validates the operation. |
IWsdl |
Exports the WSDL representation of the operation. |
IWsdl |
Exports the endpoint description as a WSDL document. |
Продукт | Версии |
---|---|
.NET | Core 1.0, Core 1.1, 8 (package-provided) |
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
UWP | 10.0 |
Отзыв о .NET
.NET — это проект с открытым исходным кодом. Выберите ссылку, чтобы оставить отзыв: