无法从传输连接读取数据:远程主机强制关闭现有连接。 [英] Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

查看:135
本文介绍了无法从传输连接读取数据:远程主机强制关闭现有连接。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误

无法从传输连接读取数据:远程主机强行关闭现有连接。

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

来自以下代码 -

FileStream fileStream = null;

             DateTime starttime = DateTime.Now;

            string str ="" ;;

            ILogger ilogger = new Logger();

            ConfigurationSettings objXConfiguration = new ConfigurationSettings();

            System.Net.ServicePointManager.Expect100Continue = false;

           试试
            {

                var username = objConfigurationSettings.UserName;

                var password = objConfigurationSettings.Password;

               使用(HttpClient的客户=新的HttpClient())

                {



                  ;   ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;



$
                     client.DefaultRequestHeaders.Accept.Add(

                        新System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(QUOT;应用程序/压缩"));



                     client.DefaultRequestHeaders.Authorization =新AuthenticationHeaderValue(QUOT;碱性" ;,

                         Convert.ToBase64String(

                             System.Text.ASCIIEncoding.ASCII.GetBytes(

                                 string.Format(" {0}:{1}",username,password))));

                     client.DefaultRequestHeaders.Add(QUOT;连接与QUOT ;,新的字符串[] {"保活"});

        &NBSP ;           // ================================================ ================================================== ===========

                 ;    string FilePath = targetdir +" \\" + BackPlanName;

                    //  string CurrentDate = DateTime.Now.Day.ToString()+" - " + DateTime.Now.Month.ToString()+" - " + DateTime.Now.Year.ToString()
+" - " + DateTime.Now.Hour.ToString()+" - " + DateTime.Now.Minute.ToString()+" - " + DateTime.Now.Second;

                 &NBSP ;  str = Project +" .zip"; $


                    如果(!Directory.Exists(文件路径))

                     {

                    &NBSP ;   Directory.CreateDirectory(文件路径);

                 &NBSP ;  }

                    fileStream = new FileStream(FilePath +" \\" + str,FileMode.Create,FileAccess.Write);



$
                    // VAR流=等待client.GetStreamAsync(QUOT; HTTPS://ariesdev.visualstudio.com/DefaultCollection/_apis/tfvc/items/$/").ConfigureAwait(continueOnCapturedContext:
假);

                    System.Net.ServicePointManager.Expect100Continue = FALSE;

                     VAR流=等待client.GetStreamAsync(sourceUrl).ConfigureAwait(continueOnCapturedContext:假);

                     await stream.CopyToAsync(fileStream).ConfigureAwait(continueOnCapturedContext:false); ; $




               ;      串CalculateSize = CalculateFileSize(文件路径+ QUOT; \\" + STR);

           &NBSP ;       对象_lock =新的对象();

                     IXMLData ixmlBackup = new XMLData();



                    的EventWaitHandle的WaitHandle =新的EventWaitHandle(真,EventResetMode.AutoReset);

              &NBSP ;     waitHandle.WaitOne();

                     ixmlBackup.CreateBackupResultXML(UtlityHelper.GetFilePath(Settings.Default.BackupResult),BackPlanName,starttime.ToString(),DateTime.Now.ToString(),
"成功" ;, CalculateSize + QUOT;文件复制");

                    waitHandle.Set();

                     // waitHandle.Dispose();



                     // ==================当窗口服务中的电子邮件时发送电子邮件======================= ==== //

                    如果(callbyservice == 1)

                 &NBSP ;  {

                    &NBSP ;   objXConfiguration = ixmlBackup.GetSettings(QUOT;申请表]);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的ObservableCollection< BackupPlan> BackupPlanCollection = ixmlBackup.GetBackupPlan();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; VAR CurrentPlan = BackupPlanCollection.Where(R => r.BackupPlanName == BackPlanName).FirstOrDefault();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的DeleteFile(CurrentPlan.KeepBackupFileCount,CurrentPlan.TargetLocation + CurrentPlan.BackupPlanName,objXConfiguration.EmailAlertLevel,
objConfigurationSettings.Service,ilogger);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果(objXConfiguration.EmailAlertLevel ==" 1 QUOT; || objXConfiguration.EmailAlertLevel ==" 2英寸)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; UtlityHelper.SendEmail(DateTime.Now.ToString()+":" + objConfigurationSettings.Service
+ QUOT;:" + BackPlanName + QUOT;&NBSP;下载&NBSP;完全",1);

                        }

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; ilogger.WriteBackLog(DateTime.Now.ToString()+":" + objConfigurationSettings.Service + QUOT;:"
+ BackPlanName + QUOT;&NBSP;下载&NBSP;完全");

                    }

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; // ================================================ ===========================
$
         ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;返回FilePath +" \\" + str;

                }
            }

FileStream fileStream = null;
            DateTime starttime = DateTime.Now;
            string str = "";
            ILogger ilogger = new Logger();
            ConfigurationSettings objXConfiguration = new ConfigurationSettings();
            System.Net.ServicePointManager.Expect100Continue = false;
            try
            {
                var username = objConfigurationSettings.UserName;
                var password = objConfigurationSettings.Password;
                using (HttpClient client = new HttpClient())
                {

                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;


                    client.DefaultRequestHeaders.Accept.Add(
                        new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/zip"));

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                        Convert.ToBase64String(
                            System.Text.ASCIIEncoding.ASCII.GetBytes(
                                string.Format("{0}:{1}", username, password))));
                    client.DefaultRequestHeaders.Add("Connection", new string[] { "Keep-Alive" });
                    //=============================================================================================================
                    string FilePath = targetdir + "\\" + BackPlanName;
                    //  string CurrentDate = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second;
                    str = Project + ".zip";

                    if (!Directory.Exists(FilePath))
                    {
                        Directory.CreateDirectory(FilePath);
                    }
                    fileStream = new FileStream(FilePath + "\\" + str, FileMode.Create, FileAccess.Write);


                    // var stream = await client.GetStreamAsync("https://ariesdev.visualstudio.com/DefaultCollection/_apis/tfvc/items/$/").ConfigureAwait(continueOnCapturedContext: false);
                    System.Net.ServicePointManager.Expect100Continue = false;
                    var stream = await client.GetStreamAsync(sourceUrl).ConfigureAwait(continueOnCapturedContext: false);
                    await stream.CopyToAsync(fileStream).ConfigureAwait(continueOnCapturedContext: false); ;


                    string CalculateSize = CalculateFileSize(FilePath + "\\" + str);
                    object _lock = new object();
                    IXMLData ixmlBackup = new XMLData();

                    EventWaitHandle waitHandle = new EventWaitHandle(true, EventResetMode.AutoReset);
                    waitHandle.WaitOne();
                    ixmlBackup.CreateBackupResultXML(UtlityHelper.GetFilePath(Settings.Default.BackupResult), BackPlanName, starttime.ToString(), DateTime.Now.ToString(), "Success", CalculateSize + " files copied");
                    waitHandle.Set();
                    // waitHandle.Dispose();

                    //==================Email when downlad compelte in window service===========================//
                    if (callbyservice == 1)
                    {
                        objXConfiguration = ixmlBackup.GetSettings("application");
                        ObservableCollection<BackupPlan> BackupPlanCollection = ixmlBackup.GetBackupPlan();
                        var CurrentPlan = BackupPlanCollection.Where(r => r.BackupPlanName == BackPlanName).FirstOrDefault();
                        DeleteFile(CurrentPlan.KeepBackupFileCount, CurrentPlan.TargetLocation + CurrentPlan.BackupPlanName, objXConfiguration.EmailAlertLevel, objConfigurationSettings.Service, ilogger);
                        if (objXConfiguration.EmailAlertLevel == "1" || objXConfiguration.EmailAlertLevel == "2")
                        {
                            UtlityHelper.SendEmail(DateTime.Now.ToString() + ":" + objConfigurationSettings.Service + ":" + BackPlanName + "  downloaded  completely", 1);
                        }
                        ilogger.WriteBackLog(DateTime.Now.ToString() + ":" + objConfigurationSettings.Service + ":" + BackPlanName + "  downloaded  completely");
                    }
                    //===========================================================================
                    return FilePath + "\\" + str;
                }
            }

问题随机出现并不频繁。请以正确的方式提供我们必须做的事情?

Issue is coming randomly not frequent. Please provide right way what we have to do?

推荐答案

感谢您在此发帖!

不确定这个问题的根本原因是什么。您可能需要查看以下链接,可能会帮助您解决此问题。

Not sure what could be the root cause of this issue. You might want to take a look at the below links, might help you resolving this.

http://stackoverflow.com/questions/24003854/visual-studio-online-build-access-denied

http://www.codeproject.com/Questions/686407/unable-to -read-data-from-the-transport-connection

http://stackoverflow.com/questions/5420656/unable-to-read-data-from-the-transport-connection-an -existing-connection-was-f 您的
耐心是值得欣赏的d。

http://stackoverflow.com/questions/5420656/unable-to-read-data-from-the-transport-connection-an-existing-connection-was-fYour patience is appreciated.

问候,

Sadiqh


这篇关于无法从传输连接读取数据:远程主机强制关闭现有连接。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆