簡體   English   中英

Azure Fluent API創建SQL Server時出錯 - 缺少x-ms-request-id標頭

[英]Azure Fluent API Error creating SQL Server - Missing x-ms-request-id header

我正在嘗試使用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.<CreateOrUpdateWithHttpMessagesAsync>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.<CreateOrUpdateAsync>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.<CreateResourceAsync>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<IResourceT>-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.<ExecuteAsync>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.<ExecuteNodeTaskAsync>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.<Create>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<ITelemetryModule>();
    var dependencyModule = modules.OfType<DependencyTrackingTelemetryModule>().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<Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule>()
    .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門戶進行檢查。

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM