c# - Can not call wcf nettcp operation in a loop in client side, which returns a byte array? -


i tried possible ways resolve issue. explain question.

i trying create file transfer mechanism using wcf nettcp service. client can request file service running in machine. file transfer happens in 3 stages.

beginfiletranfer - operation in server side, open file , ready transfer, initiate session;

[operationcontract(isinitiating = true, isterminating = false)] string beginfiletransfer(trnsfertype otype, string strfilename,string strfilepath); 

getfiledata - operation in server side, send 1024 (for time being) bytes per call opened file

[operationcontract(isinitiating = false, isterminating = false)] cfiletransferdata getfiledata(string strrequestid); 

endfiletransfer - operation in server side, close file. terminate session

[operationcontract(isinitiating = false, isterminating = true)] bool endfiletranser(string strrequestid); 

in client side call function file remote service

private void btnget_click(object sender, eventargs e) {      string strid = _agentservice.beginfiletransfer(ivayageragent.trnsfertype.get,"contacts.csv","d:");     ivayageragent.cfiletransferdata odata = null;     filestream ofile = null;         {          odata = _agentservice.getfiledata(strid);          if (odata.state == ivayageragent.transferstate.open)          {              ofile = file.create("c:\\123\\contacts.csv");              ofile.write(odata.data, 0, odata.data.length);          }          else if (odata.state == ivayageragent.transferstate.pending)          {              ofile.write(odata.data, 0, odata.data.length);          }          else          {              ofile.close();          }     }while(odata.state != ivayageragent.transferstate.close); } 

ivayageragent.cfiletransferdata

is class being used send file data client side

[datacontract] public enum transferstate : int {     [enummember]     open = 0,     pending = 1,     close = 2 } [datacontract] public class cfiletransferdata {     [datamember]     public transferstate state{get; set;}     [datamember]     public byte[] data;     [datamember]     public string status;     [datamember]     public string statusdescription; } 

problem arises when calling getfiledata in loop. first call getfiledata works fine. next subsequent call give following error

the socket connection aborted. caused error processing message or receive timeout being exceeded remote host, or underlying network resource issue. local socket timeout '00:00:59.9679982'.

this happens when send byte array data. if send nothing in array works fine. great if point out areas into. show configuration files well.

server config

<?xml version="1.0" encoding="utf-8" ?> <configuration>     <system.servicemodel>       <behaviors>         <servicebehaviors>           <behavior name="servicebehavior">             <servicemetadata />             <datacontractserializer maxitemsinobjectgraph="2147483647"/>             <servicedebug includeexceptiondetailinfaults="false" />           </behavior>         </servicebehaviors>       </behaviors>       <bindings>         <nettcpbinding>           <binding name="ivoyageragentservicebinding" receivetimeout="00:30:00">             <security mode="none"></security>             <readerquotas maxdepth="32"               maxstringcontentlength="5242880"               maxarraylength="2147483646"               maxbytesperread="4096"               maxnametablecharcount="5242880" />           </binding>         </nettcpbinding>       </bindings>       <services>           <service name="ivayageragent.ivoyageragentservice" behaviorconfiguration="">               <endpoint address="net.tcp://192.168.1.48:9020/iivoyageragentservice"                   binding="nettcpbinding" bindingconfiguration="ivoyageragentservicebinding" contract="ivayageragent.iivoyageragentservice" >               </endpoint>           </service>       </services>     </system.servicemodel> </configuration> 

client config (i @ run time, not picking configuration config file)

endpointaddress oendpointaddress = new endpointaddress("net.tcp://" + tbip.text + ":" + tbport.text + "/iivoyageragentservice");  nettcpbinding obinding = new nettcpbinding(); obinding.name = "ivoyageragentservicebinding"; xmldictionaryreaderquotas myreaderquotas = new xmldictionaryreaderquotas(); myreaderquotas.maxstringcontentlength = 5242880; myreaderquotas.maxarraylength = 2147483646; myreaderquotas.maxbytesperread = 4096; myreaderquotas.maxdepth = 32; myreaderquotas.maxnametablecharcount = 5242880;  obinding.gettype().getproperty("readerquotas").setvalue(obinding, myreaderquotas, null);   obinding.security.mode = securitymode.none; obinding.receivetimeout = new timespan(0,10,0); _channelfactory = new channelfactory<ivayageragent.iivoyageragentservice>(obinding, oendpointaddress);   _channelfactory.opened += new eventhandler(_channelfactory_opened); _channelfactory.closed += new eventhandler(_channelfactory_closed);  _channelfactory.open();   _agentservice= _channelfactory.createchannel(); 

this function build response getfiledata

[datacontract] public enum transferstate : int {     [enummember]     open = 0,     pending = 1,     close = 2 } [datacontract] public class cfiletransferdata {     [datamember]     public transferstate state{get; set;}     [datamember]     public byte[] data;     [datamember]     public string status;     [datamember]     public string statusdescription; }  public cfiletransferdata get() {     int  bnum = 0;     byte[] bdata = new byte[buffersize];     cfiletransferdata odata = new cfiletransferdata();     odata.status = "1";     odata.statusdescription = "success";       try     {           if(type == trnsfertype.get)           {               bnum = file.read(bdata, 0, (int32)buffersize);               if (bytesread == 0)               {                   odata.state = transferstate.open;               }               else               {                   if (bnum != 0)                   {                       odata.state = transferstate.pending;                   }                   else                   {                       odata.state = transferstate.close;                   }               }               odata.data = bdata;               bytesread += bnum;               bytestoread -= bnum;           }           else           {               odata.status = "0";               odata.statusdescription = "invalid transfer type";           }     }     catch     {         odata.status = "0";         odata.statusdescription = "critical error";     }     return odata; } 

please me find going wrong. thank in advance...

special asafrob efforts of trying helping me out , friend roshen. after doing days of coding able figure out going wrong. it's happening in [enummembers]

[datacontract] public enum transferstate : int {     [enummember]     open = 0,     pending = 1,     close = 2 } 

this declaration wrong if using in pending , close enum members in our response. because have not mentioned pending , close members [enummembers], in serialization process goes out , throws exception. if using member have declare it. make serialization process smooth.

this correct format... (this because of lacking of fundamentals :d)

[datacontract] public enum transferstate : int {     [enummember]     open = 0,     [enummember]     pending = 1,     [enummember]     close = 2 } 

in question told scenario. can explain why behaves that. problem arises when calling getfiledata in loop. first call getfiledata works fine. next subsequent call give following error

why working in first call is, open enum have mentioned attribute [enummember] serialize , work fine, next call set response status pending. cause serialization issue.

so thank of support , stackoverflow. hope many other.

-venura


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -