I am working on a web application that displays the Azure Service Bus Topics details when we provide the namespace connection string and topic name. Here is the code I used for this:
//To Check whether the topic is available in Azure Service Bus
private bool IsTopicAvailable(string connectionString, string path)
{
try
{
var servicebusConnectionString = new ServiceBusConnectionStringBuilder(connectionString)
{
TransportType = Microsoft.ServiceBus.Messaging.TransportType.Amqp
};
NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(servicebusConnectionString.ToString());
if (namespaceManager.TopicExists(path))
return true;
else
{
return false;
}
}
catch (Exception)
{
return false;
}
}
//To Get the Topic details
public TopicDescription GetTopic(string connectionString, string topicName)
{
var servicebusConnectionString = new ServiceBusConnectionStringBuilder(connectionString)
{
TransportType = Microsoft.ServiceBus.Messaging.TransportType.Amqp
};
NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(servicebusConnectionString.ToString());
var topic = namespaceManager.GetTopic(topicName);
return topic;
}
For this purpose, I used Microsoft.ServiceBus
Assembly.
But when I use the application through a proxy, I couldn't get the details of the topics instead of getting the exception as The remote server returned an error: (407) Proxy Authentication Required
at the line if (namespaceManager.TopicExists(path))
. But I have specified an outbound rule to allow connections made from chrome.
In few other resources I have seen that the solution for this is to set the proxy details to the WebRequest.DefaultWebProxy for eg:
var proxy = new WebProxy(data.ProxyUri);
proxy.Credentials = new NetworkCredential(data.ProxyUsername, data.ProxyPassword);
WebRequest.DefaultWebProxy = proxy;
But this approach is overriding the default proxy used in the entire application and has been reflected in other areas too. But I want to apply the proxy values only for the service bus topic call.
Can someone help me in configuring proxy for azure service bus proxy using C#.