Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2005, 01:17 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

we haven't written these classes!
can you tell where is this ASP.NET SQLServer session?I don't know IL but I think you can see their IL codes to see when it's looking for ISerializable attribute..

Hal,don't think it could be concerned with optimization issue,I assume compilers always try to optimize codes there should not be any condition.

_____________
Mehdi.
software student.
 
Old May 28th, 2005, 08:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Mehdi-

If I get some time- I might test and check the IL-- but I would certainly expect that the serializable tag does something- and since, basically, it's a directive to the complier.



Hal Levy
I am here to help you, not do it for you.
That is, unless you hire me. I am looking for work.
 
Old May 29th, 2005, 09:44 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi friends,

Formatters
A formatter is responsible for taking an object and converting it into a form that can be passed over the communication channel. The .NET Framework supplies two formatters:
  • The SoapFormatter uses XML-encoded SOAP as the message format.
  • The BinaryFormatter uses a native binary representation.
You can use either formatter with both TCP and HTTP channels. Consider the following when choosing a formatter:
  • Use the BinaryFormatter for optimized performance. Use the BinaryFormatter for optimum performance. The BinaryFormatter creates a compact binary wire representation for the data passed across the boundary. This reduces the amount of data that needs to be passed.
  • Consider Web services before using the SoapFormatter. If you need SOAP for interoperability reasons, consider using Web services ahead of the SoapFormatter with .NET remoting. Web services outperform .NET remoting, when using SOAP-based communication.
MarshalByRef vs. MarshalByValue
This section describes the two kinds of remotable objects:
  • Marshal-by-reference (MBR). The state in an MBR object remains where it is and an object reference is passed across the remoting boundary. A proxy is created and used by the client to access the object.
  • Marshal-by-value (MBV). The state in an MBV object is copied and passed across the remoting boundary. A new object with identical state is created at the recipient end.
Marshal-by-Reference
Marshal-by-reference (MBR) objects are accessed by using a proxy object in the source application domain. The .NET remoting infrastructure marshals the calls, sends them to the remote application domain, and invokes the call on the actual object.

MBR can result in chatty calls over the network if the object's interface has not been designed efficiently for remote access. Also, the client proxy may throw exceptions if the network connection breaks.

Marshal-by-reference is appropriate in the following situations:
  • Use MBR when the object state should stay in the host application domain. If the state of the object is relevant only in the host's application domain, use MBR. For example, if the object is referencing a handle to a file or other source such as a database network connection, use MBR.
    You may also want to use MBR when you do not want to serialize and send sensitive data over the network.
  • Use MBR when you need to update data frequently on the server. If the data needs to be frequently updated on the server, using a MBV may serve as a costly option. Use MBR to reduce the cost of serializing the whole of the object. The proxy marshals the data to the server's application domain.
  • Use MBR when the size of the object is prohibitively large. If the size of the object is prohibitively large, it makes sense to use MBR. In this way, the client can access the object's resource directly from the server with only the most relevant data getting passed over the network.
Marshal-by-Value
Marshal-by-value (MBV) objects declare their marshaling rules, either by implementing their own serialization by implementing the ISerializable interface, or by being marked with the Serializable attribute: Consider the following recommendations for using MBV:
  • Use MBV when you need to pass object state to the target application domain. When the state of the object is very lightweight and can easily be passed across application boundaries, use MBV objects. This reduces the lengthy, resource consuming round trips across processes, and application domain boundaries.
  • Use MBV when you do not need to update data on the server. MBV objects are appropriate when the data does not need to be updated on the server and needs only to be passed to the client. This can save server resources, network latency, and network bandwidth.
  • Use small MBV objects when you need to update data frequently on the server. If you frequently need to update data on the server, use small MBV objects where the complete state of the object is passed to the server. Using MBV reduces the marshaling and unmarshaling overhead associated with MBR, especially where non-blittable types are passed.
Serialization and Marshaling
When you use MBV, the object's state must be serialized into a byte stream and be marshaled from source to destination application domain. Serialization and marshaling costs represent a significant proportion of any .NET remoting communication overhead. Use the following recommendations to reduce this impact:
  • Consider using a data facade.
  • Marshal data efficiently and prefer primitive types.
  • Reduce serialized data by using NonSerialized.
  • Prefer the BinaryFormatter.
Consider Using a Data Facade
Consider using a data facade to wrap the most relevant data needed by the client. You can develop a wrapper object, with a coarse-grained interface, to encapsulate and coordinate the functionality of one or more objects that have not been designed for efficient remote access. It provides clients with single interface functionality for multiple business objects.

Alternatively, instead of making a remote call to fetch individual data items, you can fetch a data object by value in a single remote call. When you do that, you operate locally against the locally cached data. This might be sufficient for many scenarios.

In other scenarios, where you need to ultimately update the data on the server, the wrapper object exposes a single method which you call to send the data back to the server.

Marshal Data Efficiently and Prefer Primitive Types
A method call across a remoting boundary is expensive and slow, in comparison to in-process method calls. Make sure that you pass only the data that you need. Avoid passing data that can be simply recalculated.

.NET serialization support makes serializing an object graph very easy by using the Serializable attribute. However, if you overuse this attribute, you ensure that a large amount of extra data is passed when simpler data types would frequently suffice. Try to return value types, such as simple primitive types or structures, first. You should consider using more complex types only if these simple types are not sufficient. A classic example of extreme inefficiency is to return a DataSet that has been populated with a single row, single column value when an integer would do.

Reduce Serialized Data by Using NonSerialized
Serialize only the required data. You can reduce the amount of object state that is serialized by marking specific fields that you do not need to serialize with the NonSerialized attribute as follows.
Code:
[Serializable]
Class MyObject: MarshalByRefObject
{
  [NonSerialized]
  Private DataSet dt;
}
Note You need to use the NonSerialized attribute on both public and private fields.
Prefer the BinaryFormatter
The BinaryFormatter produces a compact data representation and should be preferred, unless you have a specific requirement for SOAP, in which case you should use Web services. You can use the BinaryFormatter with both the TcpChannel and HttpChannel.

More Information

For more information about improving the serialization performance, see "How To: Improve Serialization Performance" in the "How To" section of this guide.

Source:
http://msdn.microsoft.com/library/en...hapt11_topic15

_____________
Mehdi.
software student.
 
Old May 29th, 2005, 10:06 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

now I think its reason should be clear because in storing session in ASP.NET SQLServer objects are very small it's better to pass them by value through two application domains which indicated by

Serializable attribute makes formatters marshal objects by value
(like when we send base types(struct) by value through thread's stack in procedures)
thanks pgtips.

_____________
Mehdi.
software student.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 8: <asp:image> inside <a> & ext.CSS (pg. 274) epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 04:37 AM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
<marquee><b>About CHAT App. in PHP4</b></marquee> Ramkrishna PHP How-To 1 September 11th, 2004 07:01 AM
<STRONG> vs <B> and <EM> vs <I> anshul HTML Code Clinic 12 September 1st, 2004 05:22 PM
<<ASP.NET Security>>,download files in chapter 8 alaix All Other Wrox Books 1 July 24th, 2003 10:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.