进行Http调用时出现套接字异常

时间:2019-07-02 05:35:30

标签: c# .net http azure-functions

我有一个由App Service plan(S3)托管的Blob触发的Azure函数(v2)。该函数处理一个json文件,并使Http calls成为API管理服务中公开的API。

我正在使用HttpClient进行Http通话。尽管在具有相同设置的环境中可以正常工作,但是在另一环境中进行http post调用时却失败了。

例外:

  

System.Net.Sockets.SocketException并显示错误消息   “操作已取消。无法从传输连接中读取数据:由于线程退出或应用程序请求,I / O操作已中止。由于线程退出或线程中断,I / O操作已中止。申请请求”

快速谷歌搜索显示这可能是由于HTTP连接过多所致。此处有更多详细信息:

https://docs.microsoft.com/en-us/azure/azure-functions/manage-connections#connections-limit

解决方案是使用静态HttpClient或扩展App服务计划。我俩都只是意识到它仍然会因相同的异常而失败。

有人遇到过这个问题吗?

任何见解都会有所帮助。

编辑:这是进行http调用的代码

public class ReportingService : IReportingService
    {
        private static readonly HttpClient _httpClient = new HttpClient();
        private readonly ILogger _logger;

        public ReportingService(ILogger<ReportingService> logger, IConfigurationRoot configuration)
        {
            _logger = logger;
            _httpClient.BaseAddress = new Uri(configuration["ReportingServiceBaseUrl"]);
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{configuration["APIUser"]}:{configuration["APIPassword"]}")));
        }

        public async Task<bool> RequestReport(string endpoint, StringContent httpContent)
        {
            try
            {
                var response = await _httpClient.PostAsync(endpoint, httpContent);
                return response.IsSuccessStatusCode;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Migration failed");
                throw;
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

在后端日志中,只有执行,不幸的是失败了。

异常详细信息

时间戳:7/2/2019 6:49:55 AM 内部异常类型:System.FormatException

Full Exception :
 System.FormatException : Invalid blob path specified : ''. Blob identifiers must be in the format 'container/blob'.
   at Microsoft.Azure.WebJobs.Host.Blobs.BlobPath.ParseAndValidate(String value,Boolean isContainerBinding) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\BlobPath.cs : 53
   at Microsoft.Azure.WebJobs.Host.Blobs.Triggers.StringToCloudBlobConverter.ConvertAsync(String input,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\Triggers\StringToCloudBlobConverter.cs : 21
   at async Microsoft.Azure.WebJobs.Host.Blobs.BlobOutputConverter`1.TryConvertAsync[TInput](Object input,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\BlobOutputConverter.cs : 35
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Converters.CompositeAsyncObjectToTypeConverter`1.TryConvertAsync[T](Object value,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Converters\CompositeAsyncObjectToTypeConverter.cs : 28
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Blobs.Triggers.BlobTriggerBinding.BindAsync(Object value,ValueBindingContext context) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\Triggers\BlobTriggerBinding.cs : 158
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.TriggerWrapper.BindAsync(Object value,ValueBindingContext context) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs : 475
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding`1.BindCoreAsync[TTriggerValue](ValueBindingContext context,Object value,IDictionary`2 parameters) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\TriggeredFunctionBinding.cs : 57

请告知我您在UTC中是否有任何日期和时间

System.Net.Sockets.SocketException