c# - WCF .net streaming in chunks method calls slows down -
c# - WCF .net streaming in chunks method calls slows down -
i have client-server wcf uploader/downloader.
it downloads/uploads files in infinite loop (gets list of files , uploads/downloads them until stops it).
the client created this:
channelfactory<icontract> scf = new channelfactory<icontract>( this._endpoint.binding, this._endpoint.addressfull); this.channel = scf.createchannel(); this.channelfactory = scf;
and binding tcp client/server , created this:
public static custombinding getcustomtcpbinding(transfermode mode, long maxbufferbufferpoolsize, long maxreceivedmessagesize, int maxbuffersize, timeouthelper timeouts, streamertype st) { mtommessageencodingbindingelement binaryencoding = new mtommessageencodingbindingelement(); system.xml.xmldictionaryreaderquotas rq = binaryencoding.readerquotas; setreaderquotas(ref rq, int.maxvalue, int.maxvalue, int.maxvalue, int.maxvalue, int.maxvalue); tcptransportbindingelement tcptransport = new tcptransportbindingelement(); tcptransport.maxreceivedmessagesize = 2147483647;// maxreceivedmessagesize; tcptransport.maxbuffersize = 2147483647;// maxbuffersize; tcptransport.maxbufferpoolsize = 2147483647;// maxbufferbufferpoolsize; tcptransport.transfermode = mode; switch(st) { case streamertype.client: { //tcptransport.connectionbuffersize = consts.tcp_client_connection_buffer_size; break; } case streamertype.server: { tcptransport.connectionbuffersize = consts.tcp_server_connection_buffer_size; tcptransport.maxoutputdelay = timespan.fromseconds(30); break; } } bindingelementcollection elements = new bindingelementcollection(); elements.add(binaryencoding); elements.add(tcptransport); custombinding binding = new custombinding(elements) { name = "tcpusernamebinding" }; binding.settimeouts(timeouts); //binding.setdefaultquotas(); homecoming binding; }
and:
long maxbufferbufferpoolsize = 65536 * 4; long maxreceivedmessagesize = 2147483647; int maxbuffersize = 65536;
server is:
long maxbufferbufferpoolsize = 65536 * 4; long maxreceivedmessagesize = 2147483647; int maxbuffersize = 65536;
the download/upload streamed in chunks, stream on each read checks if each chunk size exceeded , allows more or ends.
each chunk 2mb, after next phone call made.
caller method client looks like:
public void call(action<icontract> action) { var channel = this.channel; if (channel == null) { return; } action(channel); return; }
the problem calls slower, faster, , cannot predict can cause problem.
to download use:
using (fs = new streamer.common.streamwithprogress(fstemp = new filestream(system.io.path.combine(folder, filename), system.io.filemode.openorcreate))) { fs.position = position; var res = clientconn.safecall(a => a.uploadfile(new streamer.common.remotefileinfo() { filename = filename, length = length, position = position, filebytestream = fs }), true, position == 0); position = res.position; hasnextchunk = res.hasnextchunk; }
c# .net wcf upload
Comments
Post a Comment