Thursday, 15 March 2012

c# - gzip a stream and send it with WCF -



c# - gzip a stream and send it with WCF -

i seek send gzipped stream wcf.

here code server side :

static void main(string[] args) { var baseaddress = new uri("http://localhost:2016/transferserver"); var host = new servicehost(typeof(transferserver), baseaddress); var binding = new basichttpbinding { transfermode = transfermode.streamed, maxreceivedmessagesize = long.maxvalue, maxbuffersize = 65535, }; host.addserviceendpoint(typeof(itransferserver), binding, baseaddress); var smb = new servicemetadatabehavior(); smb.httpgetenabled = true; host.description.behaviors.add(smb); host.description.behaviors.find<servicedebugbehavior>().includeexceptiondetailinfaults = true; host.open(); console.read(); }

the transferserver class :

public class transferserver : itransferserver { public void transfer(stream stream) { using (var gz = new gzipstream(stream, compressionmode.decompress)) using (var fs = new filestream("test.bin", filemode.create)) { gz.copyto(fs); } } }

client side :

public void sendstream(stream stream) { var client = new transferserverclient( new basichttpbinding {maxreceivedmessagesize = long.maxvalue, transfermode = transfermode.streamed}, new endpointaddress(@"http://localhost:2016/transferserver")); client.open(); client.transferdump( ??? gzipped stream ???); }

gzipstream compression had write stream, want send gzipped stream.

thanks

you should create own stream derived .net "stream" , implement read method

public override int read(byte[] buffer, int offset, int count) { while (count > 0) { //here should utilize gzipstream array.copy(gzipbuffer, position, buffer, offset, count); } homecoming processedbytes; }

c# wcf gzipstream

No comments:

Post a Comment