diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs index 5612218832c1f..4cbcf015667df 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs @@ -22,6 +22,7 @@ internal class HttpRequestAndResponse private readonly int _port; private readonly ClientDiagnostics _diagnostics; private readonly string _versionQuery; + private readonly string _scheme; /// /// Initializes a new which can be used to send http request and response. @@ -31,7 +32,8 @@ public HttpRequestAndResponse( ClientDiagnostics diagnostics, TokenCredential tokenCredential, string fullyQualifiedNamespace, - ServiceBusAdministrationClientOptions.ServiceVersion version) + ServiceBusAdministrationClientOptions.ServiceVersion version, + bool useTls) { _pipeline = pipeline; _diagnostics = diagnostics; @@ -39,6 +41,7 @@ public HttpRequestAndResponse( _tokenCredential = tokenCredential; _fullyQualifiedNamespace = fullyQualifiedNamespace; _port = GetPort(_fullyQualifiedNamespace); + _scheme = useTls ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; } internal void ThrowIfRequestFailed(Request request, Response response) @@ -171,7 +174,7 @@ public async Task GetEntityAsync( Uri uri = new UriBuilder(_fullyQualifiedNamespace) { Path = entityPath, - Scheme = Uri.UriSchemeHttps, + Scheme = _scheme, Port = _port, Query = queryString }.Uri; @@ -199,7 +202,7 @@ public async Task PutEntityAsync( { Path = entityPath, Port = _port, - Scheme = Uri.UriSchemeHttps, + Scheme = _scheme, Query = _versionQuery }.Uri; var requestUriBuilder = new RequestUriBuilder(); @@ -245,7 +248,7 @@ public async Task DeleteEntityAsync( Uri uri = new UriBuilder(_fullyQualifiedNamespace) { Path = entityPath, - Scheme = Uri.UriSchemeHttps, + Scheme = _scheme, Port = _port, Query = _versionQuery }.Uri; diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/ServiceBusAdministrationClient.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/ServiceBusAdministrationClient.cs index f291a92c92660..ed9edd16e87bd 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/ServiceBusAdministrationClient.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/ServiceBusAdministrationClient.cs @@ -105,12 +105,16 @@ public ServiceBusAdministrationClient( }); _clientDiagnostics = new ClientDiagnostics(options); + // The Service Bus emulator does not support TLS. + var useTls = (!connectionStringProperties.UseDevelopmentEmulator); + _httpRequestAndResponse = new HttpRequestAndResponse( pipeline, _clientDiagnostics, tokenCredential, _fullyQualifiedNamespace, - options.Version); + options.Version, + useTls); } /// @@ -211,7 +215,8 @@ private ServiceBusAdministrationClient( _clientDiagnostics, credential, _fullyQualifiedNamespace, - options.Version); + options.Version, + true); } /// diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/RequestResponseTests.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/RequestResponseTests.cs index 0cf66da4f1fc2..28dfd248d700c 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/RequestResponseTests.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/RequestResponseTests.cs @@ -20,7 +20,7 @@ public RequestResponseTests() { var options = new ServiceBusAdministrationClientOptions(); var pipeline = HttpPipelineBuilder.Build(options); - _requestResponse = new HttpRequestAndResponse(pipeline, new ClientDiagnostics(options), null, "fakeNamespace", ServiceBusAdministrationClientOptions.ServiceVersion.V2017_04); + _requestResponse = new HttpRequestAndResponse(pipeline, new ClientDiagnostics(options), null, "fakeNamespace", ServiceBusAdministrationClientOptions.ServiceVersion.V2017_04, true); } [Test] diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/ServiceBusManagementClientLiveTests.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/ServiceBusManagementClientLiveTests.cs index 664141091cd69..6519ef37734e9 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/ServiceBusManagementClientLiveTests.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/ServiceBusManagementClientLiveTests.cs @@ -11,7 +11,6 @@ using Azure.Core.TestFramework.Models; using Azure.Messaging.ServiceBus.Administration; using Azure.Messaging.ServiceBus.Authorization; -using Azure.Messaging.ServiceBus.Tests.Infrastructure; using NUnit.Framework; namespace Azure.Messaging.ServiceBus.Tests.Management