Google api Google Drive Api-复制多个文件后出错.NET-取消远程主机的连接

Google api Google Drive Api-复制多个文件后出错.NET-取消远程主机的连接,google-api,google-drive-api,google-drive-realtime-api,Google Api,Google Drive Api,Google Drive Realtime Api,下面的控制台应用程序在复制多个文件后返回异常。我想知道在.NET中使用Google drive api复制和创建文件夹的确切限制。遵循内部异常:“无法从传输连接读取数据:远程主机强制取消现有连接” static void Main(字符串[]args) { if(Debugger.IsAttached) CultureInfo.DefaultThreadCurrentUICulture=CultureInfo.GetCultureInfo(“en-US”); 字符串[]Scopes={Drive

下面的控制台应用程序在复制多个文件后返回异常。我想知道在.NET中使用Google drive api复制和创建文件夹的确切限制。遵循内部异常:“无法从传输连接读取数据:远程主机强制取消现有连接”

static void Main(字符串[]args)
{
if(Debugger.IsAttached)
CultureInfo.DefaultThreadCurrentUICulture=CultureInfo.GetCultureInfo(“en-US”);
字符串[]Scopes={DriveService.Scope.DriveReadonly,DriveService.Scope.DriveFile};
ServiceAccountCredential凭证;
使用(var)流=
新文件流(“key.json”、FileMode.Open、FileAccess.Read))
{                            
credential=GoogleCredential.FromStream(流)
.CreateScoped(范围)
.作为ServiceAccountCredential的基础凭证;
}
//创建驱动器API服务。
var service=new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer=凭证,
ApplicationName=“测试应用程序”,
});            
Google.api.Drive.v3.Data.File copiedFile=new Google.api.Drive.v3.Data.File();
对于(int i=0;i<50;i++)
{                
copiedFile.Name=“”;
copiedFile.Parents=新列表{“1I6eCYECR8lfpWP6wFDWeYkTsUMC6jKie”};
尝试
{
var lFile=service.Files.Copy(复制文件,“157cV64pH6Jdpm8SER1MQStPhnl01XHI65AsfPwSeTqw”).Execute();
WriteLine(“文件”+(i+1).ToString()+“已复制”);
}
捕获(例外e)
{                    
Console.WriteLine(“Error=“+e.InnerException.Message”);
}
}                     
}

谢谢你的帮助!我意识到我们的SonicWall防火墙阻止了一些请求。设置(Sonicwall)不阻止我们的请求后,问题得到解决。 我在这里附上了完整的错误


您是否尝试重新生成请求?也许你提出了太多的要求,这是在重新考虑一些标志。另一个可能解决问题的方法是插入一个小函数。你可以试试看,然后回来。@Raserhin谢谢你的回答!我尝试过“睡眠”,错误依然存在。我认为重拍这个请求是需要考虑的。我所关心的总是重新生成不必要的请求,并花费资源和配额。每个请求之间的间隔是多少毫秒?这是否总是发生在同一个文件号中?您可以在出现此特定错误时重试请求?@Raserhin我已将睡眠设置为1000,但错误仍然存在。我意识到,当我测试我的web应用程序时,随机创建文件夹和文件(不同的文件)。我确信,如果您在您这边运行我的控制台应用程序,您将看到错误。
static void Main(string[] args)
    {
        if (Debugger.IsAttached)
            CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("en-US");
        string[] Scopes = { DriveService.Scope.DriveReadonly, DriveService.Scope.DriveFile };            
        ServiceAccountCredential credential;                                    
        using (var stream =
                        new FileStream("key.json", FileMode.Open, FileAccess.Read))
        {                            
            credential = GoogleCredential.FromStream(stream)
                                 .CreateScoped(Scopes)
                                 .UnderlyingCredential as ServiceAccountCredential;                
        }
        // Create Drive API service.
        var service = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "Test App",
        });            
        Google.Apis.Drive.v3.Data.File copiedFile = new Google.Apis.Drive.v3.Data.File();
        for (int i = 0; i < 50; i++)
        {                
            copiedFile.Name = "";                
            copiedFile.Parents = new List<string> { "1I6eCYECR8lfpWP6wFDWeYkTsUMC6jKie" };                 
            try
            {
                var lFile = service.Files.Copy(copiedFile, "157cV64pH6Jdpm8SER1MQStPhnl01XHI65AsfPwSeTqw").Execute();
                Console.WriteLine("File " + (i+1).ToString() + " copied.");
            }
            catch (Exception e)
            {                    
                Console.WriteLine("Error = " + e.InnerException.Message);
            }
        }                     
    }