I am trying to send a message to my queue hosted in azure. My application communicates with the world through a proxy. I use the .Net Core 2.1 and the new the standard azure service bus nuget. I need to use Amqp over web sockets through the port 443. Unfortunately I have not succeed with that. Is there anybody who implemented such a thing? Can anybody provide a code snippet on how to achieve this?
Thanks in advance! Here is what I am trying:
var transportProvider = new AmqpTransportProvider();
var amqpSettings = new AmqpSettings
{
RequireSecureTransport = true, TransportProviders = {transportProvider}
};
var socketSettings = new WebSocketTransportSettings()
{
Proxy = new WebProxy() {Address = new Uri("http://myproxy"), BypassProxyOnLocal = false},
SubProtocol = "https",
Uri = new Uri($"wss://{_azureConfiguration.NameSpace}"),
};
AmqpTransportInitiator transportIntInitiator = new AmqpTransportInitiator(amqpSettings, socketSettings);
var b = transportIntInitiator.ConnectAsync(TimeSpan.FromSeconds(30), new TransportAsyncCallbackArgs());
ServiceBusConnection s = new ServiceBusConnection($"sb://{_azureConfiguration.NameSpace}", TransportType.AmqpWebSockets);
s.TokenProvider = tokenProvider;
s.OperationTimeout = TimeSpan.FromSeconds(30);
var sender = new MessageSender(s, _azureConfiguration.QueueName);
string messageBody = $"Message";
var message = new Message(Encoding.UTF8.GetBytes(messageBody));
await sender.SendAsync(message);
The code gets following error: Unable to connect to the remote server. Inner exception details: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
StackTrace:
System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server ---> System.Net.Http.HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask1.get_Result()
at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask
1.get_Result()
at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask1 creationTask)
at System.Threading.Tasks.ValueTask
1.get_Result()
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.WebSockets.WebSocketHandle.ConnectAsyncCore(Uri uri, CancellationToken cancellationToken, ClientWebSocketOptions options)
at Microsoft.Azure.ServiceBus.Core.MessageSender.OnSendAsync(IList1 messageList) in C:\source\azure-service-bus-dotnet\src\Microsoft.Azure.ServiceBus\Core\MessageSender.cs:line 562
at Microsoft.Azure.ServiceBus.RetryPolicy.RunOperation(Func
1 operation, TimeSpan operationTimeout) in C:\source\azure-service-bus-dotnet\src\Microsoft.Azure.ServiceBus\RetryPolicy.cs:line 83
at Microsoft.Azure.ServiceBus.RetryPolicy.RunOperation(Func1 operation, TimeSpan operationTimeout) in C:\source\azure-service-bus-dotnet\src\Microsoft.Azure.ServiceBus\RetryPolicy.cs:line 105
at Microsoft.Azure.ServiceBus.Core.MessageSender.SendAsync(IList
1 messageList) in C:\source\azure-service-bus-dotnet\src\Microsoft.Azure.ServiceBus\Core\MessageSender.cs:line 252