c# - How can I get a timeout exception in WCF using TcpClient Class -


i have issue i'm facing. contract implementation (besides other stuff) has this:

try             {                  response = _socketrequest.sendrequest(request, emmiterheader);                 trcode = response.tracecodeint;                 if (trcode == 0)                     statusrequest = (int) tsrequestattemptstatus.active;             }             catch (timeoutexception tex)             {                 throw;             }             catch (exception)             {                 statusrequest = (int) tsrequestattemptstatus.notactive;                 throw;             }                         {                 tsra = createtireasincorequestattemptrow(datetime.now, statusrequest, emmiterheader.headerid,                                                          string.empty,                                                          string.empty,                                                          string.empty,                                                          previouscontractnumber,                                                          taxidentificationcode,                                                          policyholdername,                                                          policyholderfirstname,                                                          policyholderlastname,                                                          registrationnumbertype.substring(0, 1),                                                          registrationnumber,                                                          ((byte) controlcodes.f),                                                          datetime.now.adddays(emmiterheader.validityperiod));             } 

then in

_socketrequest.sendrequest(request, emmiterheader);

among other stuff below:

using (var client = new tcpclient(header.socketserveraddress,                                       header.socketserverport == null ? 1 : (int)header.socketserverport))                     {                     socket socket = client.client;                          // send data timeout 10s                         //socket.send(arr);                          send(socket, arr, 0, arr.length, 1000);                          if (header.debugmode)                             _logger.loginfo(interfacename, string.format("data socket send: {0} ", temparr));                         // receive data timeout 10s                         //receive(client, arr);                          len = receive(socket, arrresponse, 0, arrresponse.length, 5000, header.debugmode, _logger);                          if (socket.connected)                             socket.close();                          if (client.connected)                             client.close();                     } 

the part under using key word never called because built in wcf client "hanging" on tcpclient part, whcich in conclusion raises socketexeption error. have set timeouts in web config lets 5 seconds. achieve throw not socket exception timeout exception. looks socketexception thrown can't make wcf service throw timeout exception. possible that? hope questin understandable want do. if not try explain can.

tcpclient not know or care talk to. has no notion of wcf, web services or timeoutexception want.

all maintain tcp connection.

catch socketexception , analyze error code stored in it. there code timeouts. throw timeoutexception yourself.


and rid of superstitious dispose stuff:

                    if (socket.connected)                         socket.close();                      if (client.connected)                         client.close(); 

once enough.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -