Azure Fluent API创建SQL Server时出错 – 缺少x-ms-request-id标头

我正在尝试使用Azure Fluent API( https://github.com/Azure/azure-sdk-for-net/tree/Fluent )创建一个新的SQL Server,但我总是得到一个Microsoft.Rest.Azure.CloudException 。 其他所有(创建存储帐户,应用程序服务,资源组)工作正常 – 它只是SQL部分不起作用。

ISqlServer sqlServer = await Azure.SqlServers .Define(serverName) .WithRegion(regionName) .WithExistingResourceGroup(rgName) .WithAdministratorLogin(administratorLogin) .WithAdministratorPassword(administratorPassword) .WithNewElasticPool(elasticPoolName, elasticPoolEdition) .CreateAsync(); 

但是在尝试创建服务器时,我得到了一个例外:

 {Microsoft.Rest.Azure.CloudException: Invalid value for header 'x-ms-request-id'. The header must contain a single valid GUID. at Microsoft.Azure.Management.Sql.Fluent.ServersOperations.d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Management.Sql.Fluent.ServersOperationsExtensions.d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Management.Sql.Fluent.SqlServerImpl.d__53.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Management.ResourceManager.Fluent.Core.ResourceActions.Creatable`4.<Microsoft-Azure-Management-ResourceManager-Fluent-Core-ResourceActions-IResourceCreator-CreateResourceAsync>d__15.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Management.ResourceManager.Fluent.Core.DAG.CreatorTaskItem`1.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Management.ResourceManager.Fluent.Core.DAG.TaskGroupBase`1.d__14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at XircuitAPI.Controllers.AzureSqlServerController.d__9.MoveNext() in C:\Users\ThimoBuchheister\Documents\Code\Xircuit\xircuit\XircuitAPI\Controllers\AzureSqlServerController.cs:line 235} 

好吧,我已经解决了我的问题,在使用小提琴跟踪我的http请求后我发现,Application Insights在我的AAD应用程序请求中添加了标题。 所以我完全删除了应用程序见解,并重新上线。 希望它能帮到你。 看这个。 如果您想继续使用Application Insight,请选中此选项以禁用应用程序洞察

您所要做的就是排除在此链接中编写的域或其他选项。

https://blog.wille-zone.de/post/disable-application-insights-correlation-id-headers-on-httpclient-requests-in-aspnet-core/

  var modules = app.ApplicationServices.GetServices(); var dependencyModule = modules.OfType().FirstOrDefault(); if (dependencyModule != null) { var domains = dependencyModule.ExcludeComponentCorrelationHttpHeadersOnDomains; domains.Add("management.azure.com"); } 

对于那些不在.NET Core但在Web API或ASP.NET MVC 5上的用户,请访问以下模块:

 var dependencyModule = Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryModules.Instance.Modules .OfType() .FirstOrDefault(); if (dependencyModule != null) { var domains = dependencyModule.ExcludeComponentCorrelationHttpHeadersOnDomains; domains.Add("management.azure.com"); } 

我无法重复您在Microsoft.Azure.Management.Sql.Fluent SDK 1.1.3版中提到的问题。 以下是我的详细步骤:

准备

注册表一个AD应用程序和assgin应用程序到相应的角色,更多细节请参考Azure官方教程 。 之后,我们可以从Azure门户获取tenantIdappId密钥

脚步:

1.创建.net核心C#控制台项目。

2.参考Microsoft.Azure.Management.Sql.Fluent SDK,更多细节请参考以下截图

3.将以下代码添加到Program.cs文件中。

 string clientId = "xxxxxxx"; string secretKey = "xxxxxxx"; string tenantId = "xxxxxxx"; var credentials = new AzureCredentials(new ServicePrincipalLoginInformation { ClientId = clientId, ClientSecret = secretKey }, tenantId, AzureEnvironment.AzureGlobalCloud); var azure = Azure .Configure() .Authenticate(credentials) .WithDefaultSubscription(); var serverName = "tomtestsqlazure";//test sql name var regionName = Region.AsiaEast.ToString(); //region name var administratorLogin = "tom"; var administratorPassword = "xxxxxxx"; var rgName = "xxxxx"; //resource group name var elasticPoolName = "testelastic"; var elasticPoolEdition = "standard"; ISqlServer sqlServer = azure.SqlServers .Define(serverName) .WithRegion(regionName) .WithExistingResourceGroup(rgName) .WithAdministratorLogin(administratorLogin) .WithAdministratorPassword(administratorPassword) .WithNewElasticPool(elasticPoolName, elasticPoolEdition) .CreateAsync().Result; 

4.来自当地的调查并与小提琴手一起接受请求。

在此处输入图像描述

在此处输入图像描述

5.从Azure门户进行检查。

在此处输入图像描述