为什么交易在网络中被延迟

时间:2013-03-13 08:01:11

标签: c# http post webclient

我使用WebClient类的Upload File方法使用Http Post Method将事务发布到服务器。在将事务发布到服务器之前,我将使用当前日期和时间保留此请求的日志,并使用wireshark进行网络日志。如果我比较两个日志文件的时间,则相同事务的总时间差为15-30秒,即使两者都在同一服务器上(网络日志显示15-30秒的时间延迟)。

我很惊讶导致网络延迟的原因是将其记录到日志文件后我立即将此事务发布到服务器。

我用于发布交易的方法是: -

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;
        }

0 个答案:

没有答案