1

I am using Upload File method of WebClient class to post transactions to server by using Http Post Method. Before posting transaction to server I am keeping log of this request with current date and time and also using wireshark for network logs. If I compare time of both log files there are always time difference of 15-30 seconds for same transaction even both are at the same server(Network logs showing time delay of 15-30 seconds).

I am surprised what is causing this delay in network as after logging it into log file I am immediately posting this transaction to server.

Method I am using for posting transaction is :-

private BankCommonLayer.httpsResponse SendhttpsMessage(string strRequest, string RRN)
        {
            BankCommonLayer.httpsResponse hr = new BankCommonLayer.httpsResponse();
            string strDirName = ConfigurationSettings.AppSettings["Attachment_file"];
            try
            {
                string strFileName = strDirName + RRN + ".txt";

                Microsoft.VisualBasic.FileIO.FileSystem.WriteAllText(strFileName, HexToAscii(strRequest), false, System.Text.Encoding.GetEncoding(28591));

                FileInfo fi = new FileInfo(strFileName);
                NameValueCollection q = new NameValueCollection();

                q.Add("Message", fi.Name);

                string url = ConfigurationSettings.AppSettings["https_url"];
                WebClient wc = new WebClient();

                wc.QueryString = q;

                string ResultString = string.Empty;
                byte[] postBytes = wc.UploadFile(url, "POST", strFileName);

                if (postBytes.Length != 0)
                    hr.ResponseString = System.Text.Encoding.ASCII.GetString(postBytes).ToString();
                else
                    hr.ResponseString = "No response";

                BLCommonFunctions.WriteLogger(1, "FIG Response string      :- " + hr.ResponseString.ToString(), ref swLogWriter, strLogPath);
                //Write the string to a file.
                System.IO.StreamWriter file = new System.IO.StreamWriter(strFileName, true);
                file.WriteLine();
                file.WriteLine("Response String :" + hr.ResponseString);

                file.Close();

                Console.WriteLine(hr.ResponseString);
                hr.SendSuccess = true;
            }
            catch (WebException ex)
            {
                hr.SendSuccess = false;
                BLCommonFunctions.WriteLogger(1, "FIG Response string      :- NULL (Because " + ex.Message + ")", ref swLogWriter, strLogPath);
            }
            catch (Exception ex)
            {
                hr.SendSuccess = false;
                BLCommonFunctions.WriteLogger(1, "FIG Response string      :- NULL (Because " + ex.Message + ")", ref swLogWriter, strLogPath);
            }
            return hr;
        }
user1888859
  • 243
  • 1
  • 3
  • 11
  • check this: [System.Net.WebClient unreasonably slow](http://stackoverflow.com/questions/4415443/system-net-webclient-unreasonably-slow). Maybe u need to set proxy of WebClient to null. – a3.14_Infinity Mar 13 '13 at 08:05

0 Answers0