我可以为cosmos db项目使用默认代理吗

时间:2019-06-26 12:22:19

标签: azure-cosmosdb asp.net-core-webapi

我已经使用cosmos db和asp.net core完成了一项服务。对于WiFi,它可以正常工作,但是当我尝试使用默认代理时,会给出错误消息。

SocketException: Resource temporarily unavailable
System.Net.Http.ConnectHelper.ConnectAsync(string host, int port, CancellationToken cancellationToken)
HttpRequestException: Resource temporarily unavailable
System.Net.Http.ConnectHelper.ConnectAsync(string host, int port, CancellationToken cancellationToken)

DocumentClient创建代码示例:

  public async Task<IEnumerable<Product>> FetchProductListAsync(
         Guid? itemId)
        {

            var feedOptions =
                  new FeedOptions
                  {
                      MaxItemCount = -1,
                      EnableCrossPartitionQuery = true
                  };

            var query =
                $"SELECT  product.Id,product.Name,product.MethodOfPreparation,product.Addons,product.CurrentQuantity,product.Tag,product.Unit,product.Price FROM catalog join industry in catalog.Industy join category in industry.Category join Subcategory in category.Subcategory  join product in Subcategory.Product where catalog.id = '" + itemId + "'";

            var queryDefinition =
                new SqlQuerySpec(query);



            var orderDocumentQuery =
                 _docClient.CreateDocumentQuery<Product>(
                     UriFactory.CreateDocumentCollectionUri(
                         _azureCosmosDbOptions.Value.DatabaseId, "catalog"), queryDefinition, feedOptions)
                     .AsDocumentQuery();

           var childrenSqlQuery = _docClient.CreateDocumentQuery(UriFactory.CreateDocumentCollectionUri(_azureCosmosDbOptions.Value.DatabaseId, "catalog"), query).ToString();


            Console.WriteLine(childrenSqlQuery);
            Console.WriteLine(childrenSqlQuery);
            var orderList =
                new List<Product>();


            while (orderDocumentQuery.HasMoreResults)
            {
                orderList.AddRange(
                    await orderDocumentQuery.ExecuteNextAsync<Product>());
                Console.WriteLine(orderList);
            }

            return orderList;
        }

我正在使用DucumentDb.Core 2.4.1,请给我个提示。

1 个答案:

答案 0 :(得分:0)

在node js sdk中,您可以直接设置ProxyUrl属性。(How to use DocumentDB behind a Proxy in NodeJS

但是,它在.NET sdk中没有这样的属性。在这种情况下,您可以尝试以下配置:CosmosDB C# SDK ProyUrl missing

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true">
        <proxy usesystemdefault="True" />
    </defaultProxy>
</system.net>

但是,我注意到trace中仅支持.net,而不支持.net核心。因此,请参考以下案例:asp.net core defaultProxy