我做了一个服务程序,和一个客户程序。
我通过客户程序调用服务器程序 对一个byte型数组进行反序列化。
但是在客户端调用时就会抛异常:说是 服务器无法处理。
然后会提示是反序列化出的问题,请各位高人指点一下哇。
=======================================================================================================
异常:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Runtime.Serialization.SerializationException: Unable to find assembly 'ClientForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at SeverviceWrong.App_Code.Serialize.SerializeDIY.ByteArrayToObject(Byte[] b) in E:\Graduate\SeverWrong\WebService1\App_Code\Serialize\SerializeDIY.cs:line 33
at SeverviceWrong.ServiceWrong.GetObjectFromClient(String Clmd5hash, Byte[] Clcrypt) in E:\Graduate\SeverWrong\WebService1\ServiceWrong.asmx.cs:line 95
======================================================================================================
我序列化和反序列化的代码:
public class SerializeDIY
{
//实现序列化的方法
public static byte[] ObjectToByteArray(object c)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter b = new BinaryFormatter();
b.Serialize(ms, c);
ms.Close();
return ms.ToArray();
}
//实现反序列化的方法
public static object ByteArrayToObject(byte[] b)
{
MemoryStream ms = new MemoryStream(b, 0, b.Length);
BinaryFormatter bb = new BinaryFormatter();
return bb.Deserialize(ms);
}
}