ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 序列化二:WebService参数序列化

序列化二:WebService参数序列化

原创 Linux操作系统 作者:kirinri 时间:2008-01-10 20:27:22 0 删除 编辑

前不久使用Webservice,传递参数为Hashtable,或是Arraylist中装载着Hashtable.
着实因为HT不能序列化难住了一下.现将序列化的方法备份.

using

System;

using

System.IO;

using

System.Collections;

using

System.Xml.Serialization;

using

System.Runtime.Serialization.Formatters.Binary;

namespace

{

My.Utilities///

/// Summary description for Serialize.

///

{

{

}

public class Serializepublic Serialize()///

/// ArrayList --> byte[]

///

/// ArrayList

/// byte[]

{

XmlSerializer x =

MemoryStream m =

public static byte[] SerializeArrayList(ArrayList arr)null;null;byte[] brr;try

{

x =

m =

x.Serialize(m,arr);

brr = m.ToArray();

}

{

}

new XmlSerializer(typeof(ArrayList));new MemoryStream();return brr;catch (Exception ex)throw ex;finally

{

m.Close();

}

}

if (m != null)///

/// byte[] --> ArrayList

///

/// byte[]

/// ArrayList

{

XmlSerializer x =

MemoryStream m =

ArrayList arr;

public static ArrayList DeSerializeArrayList(byte[] brr)null;null;try

{

x =

m =

arr = (ArrayList)x.Deserialize(m);

}

{

}

new XmlSerializer(typeof(ArrayList));new MemoryStream(brr);return arr;catch (Exception ex)throw ex;finally

{

{

m.Close();

}

}

}

if (m != null)///

/// Hashtable --> byte[]

///

/// Hashtable

/// byte[]

{

BinaryFormatter b =

MemoryStream m =

public static byte[] SerializeHashtable(Hashtable ht)null;null;byte[] brr;try

{

b =

m =

b.Serialize(m,ht);

brr = m.ToArray();

}

{

}

new BinaryFormatter();new MemoryStream();return brr;catch (Exception ex)throw ex;finally

{

m.Close();

}

}

if(m != null)///

/// byte[] --> Hashtable

///

/// byte[]

/// Hashtable

{

BinaryFormatter b =

MemoryStream m =

Hashtable ht;

public static Hashtable DeSerializeHashtable(byte[] brr)null;null;try

{

b =

m =

ht = (Hashtable)b.Deserialize(m);

}

{

}

new BinaryFormatter();new MemoryStream(brr);return ht;catch (Exception ex)throw ex;finally

{

m.Close();

}

}

if (m != null)///

/// Arraylist include with Hashtable

/// Arraylist --> byte[]

///

/// Arraylist[Hashtable]

/// byte[]

{

ArrayList arr1 =

{

Hashtable ht = (Hashtable)arr[i];

arr1.Add(SerializeHashtable(ht));

}

brr = SerializeArrayList(arr1);

}

public static byte[] SerializeArrayListWithHashTabls(ArrayList arr)byte[] brr;new ArrayList();for(int i = 0; i < arr.Count; i++)return brr;///

/// Arraylist include with Hashtable

/// byte[] --> Arraylist

///

/// byte[]

/// Arraylist[Hashtable]

{

ArrayList arr =

ArrayList arr2 =

arr = DeSerializeArrayList(brr);

{

arr2.Add(DeSerializeHashtable((

}

}

}

}

public static ArrayList DeSerializearrayListWithhashTables(byte[] brr)null;new ArrayList();for(int i = 0; i < arr.Count; i++)byte[])arr[i]));return arr2;
发表于:2007.08.07 14:25

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12476590/viewspace-134139/,如需转载,请注明出处,否则将追究法律责任。

下一篇: DotNet-MD5
请登录后发表评论 登录
全部评论

注册时间:2007-12-21

  • 博文量
    257
  • 访问量
    500384