1
votes

I am trying to get started with Azure Service Bus queues. following this article https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues the only difference is that I am trying to do this from within a web api.
The error I get is: No connection could be made because the target machine actively refused it 40.84.xxx.xx:443

I'd appreciate any help or pointers!

Note: Console app works just fine following the above guide.

Updated 7/24, this is the code in my action method:

   try
        {
            var connectionString =
                "Endpoint=sb://xxxxx-test.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=shared_access_key";
            var queueName = "testqueue1";

            var client = 
    QueueClient.CreateFromConnectionString(connectionString, queueName);

            var message = new BrokeredMessage(eventMessage);
            client.Send(message);
        }
        catch (Exception e)
        {
          //log exception
        }

Update 7/25. I was able to make it work by setting defaultConfig entry as enabled in web.config:

 <system.net>
   <defaultProxy enabled="true"/>
 </system.net>
2
@Maxime if this was a network issue or firewall issue, the console app should also get this same error - which is not the case.the_sheikh
@the_sheikh creating client is an expensive operation. You should look into changing your code to keep the client for a longer time.Sean Feldman
Aside from that, your code looks fine. It's an infrastructure issue like others pointed out.Sean Feldman
@SeanFeldman are you suggesting to keep the QueueClient instance static, like httpClient? my azure code worked after adding defaultProxy entry in web.config. i am still trying to figure out why this is not needed in case of a console app.the_sheikh

2 Answers

1
votes

No connection could be made because the target machine actively refused it 40.84.xxx.xx:443

Please check whether the outbound 443 port is blocked by your firewall.

Note: Console app works just fine following the above guide.

The default value of connectivity mode for Service Bus is AutoDetect. It will automatically selects between the Tcp and Http modes based on an auto-detection mechanism that probes whether either connectivity option is available for the current network environment. It maybe choose different modes for your Console App and Web API application. Try to set it to TCP explicitly in your Web API application before using the Service Bus Queue.

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Tcp;
1
votes

I was able to make it work by setting defaultConfig entry as enabled in web.config:

<system.net>
  <defaultProxy enabled="true"/>
</system.net>