开发者

'System.IO.Compression.GZipStream' cannot be serialized. Consider marking it with the DataContractAttribute attribute

开发者 https://www.devze.com 2023-04-03 01:53 出处:网络
I am trying to use WCF service to upload GZip files. Im trying to compress files using Gzip and then passing it through to WCF service to be uploaded to server.

I am trying to use WCF service to upload GZip files. Im trying to compress files using Gzip and then passing it through to WCF service to be uploaded to server. Every time I'm running the code I get this error message

'System.IO.Compression.GZipStream' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its memb开发者_开发知识库ers you want serialized with the DataMemberAttribute attribute.

I have marked this property member to be [DataMember]. I have also done the [DataContract] and below that added [Serialiable] which is not needed to be honest.

Can any one help?


I am not too sure this is a proper way, but it worked for me.

1) Create a Data Transfer Object class

[DataContract]
class ZippedDataDTO
{
    [DataMember]
    public byte[] RawData {get;set;}

    //other relevant metadata
}

2) Once data is compressed, get bytes from the stream, smth like .ToArray()

3) Assign the zipped raw bytes to DTO's RawBytes

4) Return this DTO as a part of your WCF service contract

[ServiceContract]
interface IService
{
    [OperationContract]
    ZippedDataDTO GetZippedData();  
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消