public sealed class BinaryFormatter : IRemotingFormatter, IFormatter
|
During RPCs, the IRemotingFormatter interface allows the specification of two separate object graphs: the graph of objects to serialize, and an additional graph containing an array of header objects that convey information about the remote function call (for example, transaction ID or a method signature).
RPCs that use the BinaryFormatter separate into two distinct parts: method calls, which are sent to the server with the remote object containing the method called, and method responses, which are sent from the server to the client with the status and response information from the called method.
During serialization of a method call the first object of the object graph must support the IMethodCallMessage interface. To deserialize a method call, use the BinaryFormatter.Deserialize method with the HeaderHandler parameter. The remoting infrastructure uses the HeaderHandler delegate to produce an object that supports the ISerializable interface. When the BinaryFormatter invokes the HeaderHandler delegate, it returns the URI of the remote object with the method that is being called. The first object in the graph returned supports the IMethodCallMessage interface.
The serialization procedure for a method response is identical to that of a method call, except the first object of the object graph must support the IMethodReturnMessage interface. To deserialize a method response, use the BinaryFormatter.DeserializeMethodResponse method. To save time, details about the caller object are not sent to the remote object during the method call. These details are instead obtained from the original method call, which is passed to the BinaryFormatter.DeserializeMethodResponse method in the IMethodCallMessage parameter. The first object in the graph returned by the BinaryFormatter.DeserializeMethodResponse method supports the IMethodReturnMessage interface.
ctor #1 | Overloaded:.ctor() Default constructor. This constructor is called by derived class constructors to initialize state in this type.Initializes a new instance of the BinaryFormatter class with default values. |
ctor #2 | Overloaded:.ctor(ISurrogateSelector selector, StreamingContext context) Initializes a new instance of the BinaryFormatter class with a given surrogate selector and streaming context. |
AssemblyFormat | Read-write Gets or sets the format in which assembly names are serialized. |
Binder | Read-write Gets or sets an object of type SerializationBinder that controls the binding of a serialized object to a type. |
Context | Read-write Gets or sets the StreamingContext for this formatter. |
SurrogateSelector | Read-write Gets or sets an ISurrogateSelector that controls type substitution during serialization and deserialization. |
TypeFormat | Read-write Gets or sets the format in which type descriptions are laid out in the serialized stream. |
Deserialize | Overloaded:Deserialize(Stream serializationStream) Deserializes the specified stream into an object graph. |
Deserialize | Overloaded:Deserialize(Stream serializationStream, HeaderHandler handler) Deserializes the specified stream into an object graph. The provided HeaderHandler handles any headers in that stream. |
DeserializeMethodResponse | Deserializes a response to a remote method call from the provided Stream. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
Serialize | Overloaded:Serialize(Stream serializationStream, object graph) Serializes the object, or graph of objects with the specified top (root), to the given stream. |
Serialize | Overloaded:Serialize(Stream serializationStream, object graph, Header[] headers) Serializes the object, or graph of objects with the specified top (root), to the given stream attaching the provided headers. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public BinaryFormatter(); |
Property Type | Condition |
---|---|
BinaryFormatter.SurrogateSelector | null . |
BinaryFormatter.Context | A StreamingContext with a value indicating that serialized data can be transmitted to or received from any of the other contexts. ( StreamingContextStates.All ). |
public BinaryFormatter( |
selector
context
The serialization or deserialization process uses the specified ISurrogateSelector to search for surrogates that are registered for the object types you want to deserialize. Surrogates are helpers that serialize and deserialize objects of specific classes. The default ISurrogateSelector cannot handle the serialization of objects that derive from the MarshalByRefObject for remoting purposes. In a remoting situation the specified ISurrogateSelector replaces the object derived from MarshalByRefObject with an ObjRef object that is serialized by the specified surrogate selector. Therefore, if you want to use remote objects, set the selector parameter to an instance of RemotingSurrogateSelector. If you do not need surrogates, set the selector argument to be null.
public FormatterAssemblyStyle AssemblyFormat {get; set;}
|
public SerializationBinder Binder {get; set;}
|
public StreamingContext Context {get; set;}
|
public ISurrogateSelector SurrogateSelector {get; set;}
|
public FormatterTypeStyle TypeFormat {get; set;}
|
serializationStream
Exception Type | Condition |
---|---|
ArgumentNullException | serializationStream is null. |
SerializationException | serializationStream supports seeking, but its length is 0. |
public object Deserialize( |
serializationStream
handler
Exception Type | Condition |
---|---|
ArgumentNullException | serializationStream is null. |
SerializationException | serializationStream supports seeking, but its length is 0. |
public object DeserializeMethodResponse( |
serializationStream
handler
methodCallMessage
Exception Type | Condition |
---|---|
ArgumentNullException | serializationStream is null. |
SerializationException | serializationStream supports seeking, but its length is 0. |
~BinaryFormatter(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
serializationStream
graph
Exception Type | Condition |
---|---|
ArgumentNullException | serializationStream is null. |
SerializationException | An error has occurred during serialization, such as if an object in the graph parameter is not marked as serializable. |
serializationStream
graph
headers
Exception Type | Condition |
---|---|
ArgumentNullException | serializationStream is null. |
SerializationException | An error has occurred during serialization, such as if an object in the graph parameter is not marked as serializable. |
public virtual string ToString(); |