|
发表于 2021-4-23 13:00:02
|
显示全部楼层
最简单的办法把对象数组用2进制序列化成byte[]
然后webservice端反序列化成想要的对象数组,调用结束后再序列化成byte[]返回,客户端再反序列化得到结果
[WebMethod]
public byte[] WebInvoke( byte[] data )
{
}
public class Serializer
{
private BinaryFormatter bf;
public Serializer()
{
this.bf = new BinaryFormatter();
}
public byte[] BinarySerialize(object obj)
{
if (obj == null)
{
throw new ArgumentNullException("obj");
}
MemoryStream stream1 = new MemoryStream();
this.bf.Serialize(stream1, obj);
return stream1.ToArray();
}
public object BinaryDeserialize(byte[] data)
{
if (data == null)
{
return null;
}
MemoryStream stream1 = new MemoryStream(data);
return this.bf.Deserialize(stream1);
}
} |
|