客户端
main()
{
         string[] temp  = CommonFunction.SerializeDBObject(dbobject);
WebService dataService = new WebService();
int nResult = dataService.AddObject(temp);
}
public static string[] SerializeDBObject(DBObject ds)     

// 序列化对象 
BinaryFormatter    binaryFormatter    = new BinaryFormatter(); 
 
// 创建一个内存流,序列化后保存在其中 
MemoryStream ms    = new MemoryStream(); 
byte[] b; 
 
// 将DBObject对象序列化为内存流 
// 
binaryFormatter.Serialize(ms, ds); 
 
// 设置内存流的起始位置 
// 
ms.Position    = 0; 
         
// 读入到 byte 数组 
// 
b =    new   Byte[ms.Length]; 
ms.Read(b, 0, b.Length); 
ms.Close();  string[]  temp = new string[b.Length];

for(int i = 0 ; i < b.Length ; i++)
{
temp[i] = b[i].ToString();
}  
return temp; 
} 服务端:
[WebMethod]
public int AddObject(string[] b)
{
 DBObject lawobject = DeserializeDBObject(b);
 return DbObjectAccess.AddObject(lawobject);
}public DBObject DeserializeDBObject(string[] objectString)  

 
DBObject db= new DBObject(); byte[] serializedDBObject = new byte[objectString.Length];; for(int i = 0 ; i < objectString.Length ; i++)
serializedDBObject[i] = byte.Parse(objectString[i]); if (serializedDBObject.Length    == 0) 
return null; 
try     

BinaryFormatter    binaryFormatter    = new BinaryFormatter(); 
MemoryStream ms    = new MemoryStream(); 
 
// 将 byte 数组到内存流 
// 
ms.Write(serializedDBObject, 0, serializedDBObject.Length); 
 
// 将内存流的位置到最开始位置 
// 
ms.Position    = 0; 
 
// 反序列化成DBObject对象,创建出与原对象完全相同的副本 
// 
db = (DBObject) binaryFormatter.Deserialize(ms); 
 
ms.Close();  return db;
}  
catch(Exception ex)
{
return null;
}     
} 现在运行系统提示:无法找到程序集请教......

解决方案 »

  1.   

    不想看这么长的代码。无法找到程序集是没有引用或是少了using啊。
      

  2.   

    序列化是Remoting 里面的东东,怎么又跑到WebService里面去了!
      

  3.   

    出错是在db = (DBObject) binaryFormatter.Deserialize(ms); 这句to:MyLf(不睡觉的鱼) 少了using编译可以通过么?
      

  4.   

    我只是有点奇怪,你的byte[i].tostring 和 byte.Parse(objectString[i] 能保证不出问题么至于没找到程序集,会不会是 DBObject 强制类型转换引发的
      

  5.   

    ???? 为何要把 对象 转换为string[]
    byte[] 可以在webSerive 传递的!而且string 比 byte 大的!
      

  6.   

    你要保证你的 DBObject 类在一个dll中而且,
    服务端和客户端都要有这个dll并且引用了。
    如果 传递的是继承了 DBObject 的子类,子类
    也要两边都有!
      

  7.   

    谢谢,已经解决,就是 FlashElf(銘龘鶽) 所说的,我那个类写在exe文件里面了,现已改成DLL
    至于byte[]改成string[]是因为我原来这么做的时候.net报错,后来调了一下又可以了...
    多谢...