class="article_content clearfix">
class="htmledit_views">
class="postTitle">MarshalByRefObject和Serializable
class="postBody">
[Serializable]
public class
serialze:ISerializable
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
// 序列化函数,由 SoapFormatter 在序列化过程中调用
void
ISerializable.GetObjectData(SerializationInfo info, StreamingContext
ctxt)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// 向 SerializationInfo 对象中添加每个字段
info.AddValue("UserName"
, UserName);
info.AddValue("UserID"
,UserID);
}
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 还原序列化构造函数,由 SoapFormatter 在还原序列化过程中调用
public
serialze(SerializationInfo info, StreamingContext ctxt)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// 从 SerializationInfo 对象中还原序列化出各个字段
UserName = (class="tags" href="/tags/STRING.html" title=string>string)info.GetValue("UserName", typeof(class="tags" href="/tags/STRING.html" title=string>string
));
UserID = (int) info.GetValue("UserID",typeof(int
));
}
public
serialze()
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{}
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public class="tags" href="/tags/STRING.html" title=string>string
UserName;
public int
UserID;
}
转自:http://hi.baidu.com/smile8021/blog/item/f6b81e0aa870713db1351d82.html(天天向上)
最近在看class="tags" href="/tags/WEB.html" title=web>web sevice 方面的东西,顺便看了下序列化,懂了不少啊 :
从MarshalByRefObject派生的类和有[Serializable]的类都可以跨越应用程序域作为参数传递。
从MarshalByRefObject派生的类按引用封送,有[Serializable]标志的类,按值封送。
如果此类即从MarshalByRefObject派生,也有[Serializable]标志也是按引用封送。
序列化有3种情况:
- 序列化为XML格式:
在class="tags" href="/tags/WEBSERVICE.html" title=class="tags" href="/tags/WEB.html" title=web>webservice>class="tags" href="/tags/WEB.html" title=web>webservice里,写个class="tags" href="/tags/WEB.html" title=web>web method,传个自定义类做参数,就是这种情况。系统会帮你搞定,把自定义的类转换为默认XML格式。 - 序列化为2进制:
要加[Serializable]标志,可以把私有变量和公共变量都序列化。 - 序列化为class="tags" href="/tags/SOAP.html" title=soap>soap格式:
需要实现ISerializable接口,定义序列化函数ISerializable.GetObjectData,和还原序列化的构造函数。
一个class="tags" href="/tags/SOAP.html" title=soap>soap参数类的sample:
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.cnblogs.com/Images/dot.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.cnblogs.com/Images/dot.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.cnblogs.com/Images/dot.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](http://www.cnblogs.com/Images/dot.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)