I am trying to get started with Azure Service Bus queues. following this article
https://learn.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>
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;
I was able to make it work by setting defaultConfig entry as enabled in web.config:
<system.net>
<defaultProxy enabled="true"/>
</system.net>
Related
I am currently having some issues with class library that doesn't behave as its console app.
The purpose of the console app is to send messages to an azure queue, which it does without any problem, and can see in ressource monitor that it makes calls through our web proxy and to our azure queue. This is done by default, I haven't told it anyway that it should use this proxy.
The class library on the other hand, does the same thing, but does not use the proxy, and therefore not able to send its data.
Both projects are identical, in the way they make the call to send a message, but for some reason is the console app, which intention is only to send a message, and library which intention is the same, act differently - why does the console app try to use proxy, and how do i force the class library to forcefully use the proxy?
conclusion:
How do i force a Microsoft.ServiceBus.Messaging.QueueClient.send
to use a proxy and not port 443
Per my knowledge, It is impossible to set the proxy while using service bus client.
The only connection options for Service Bus client are as following:
HTTP - port 80
HTTPS - port 443
TCP - 9350 to 9354
For more information we can refer to:
ConnectivityMode Enum
In your class library, please set the connectivity mode to Http as below code and try again:
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
Similar thread as yours: Azure Service Bus working behind proxy
To answer my own question.
I resolved the issue by creating a proxy.config , and add it to my app.config.
proxy.config format:
<?xml version="1.0"?>
<defaultProxy enabled="true">
<proxy autoDetect="False" proxyaddress="http://<proxyaddress>:<port>" />
<bypasslist>
<add address="localhost" />
</bypasslist>
</defaultProxy>
and add the proxy.config into my app.config as a system.net configuration:
<system.net>
<defaultProxy configSource="proxy.config" />
</system.net>
I have Fiddler running on port 8888
Web.config:
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy bypassonlocal="False" proxyaddress="http://localhost:8888" usesystemdefault="False" autoDetect="False" />
</defaultProxy>
</system.net>
App code (specifies credentials for the API controller its talking to):
var wc = new WebClient();
wc.Proxy = new WebProxy(new Uri($"http://localhost:8888"), false);
wc.Credentials = new NetworkCredential("myuser", "mypass");
var response = wc.UploadString("http://localhost:11026/api/mycontroller/mymethod", "POST", request);
I cannot for the life of me get it to communicate via Fiddler so I can debug requests. Am I doing something wrong?
UPDATE
This information is supplied by Fiddler help but having used localhost.fiddler in both web.config and app code, still not being captured by Fiddler (and when Fiddler is closed it doesn't cause a connection failed error)
Solution 2: Use http://ipv4.fiddler
Use http://ipv4.fiddler to hit localhost on the IPv4 adapter. This
works especially well with the Visual Studio test webserver (codename:
Cassini) because the test server only listens on the IPv4 loopback
adapter. Use http://ipv6.fiddler to hit localhost on the IPv6 adapter,
or use http://localhost.fiddler to hit localhost using "localhost" in
the Host header. This last option should work best with IIS Express.
Rather than trying to send it via the proxy, send it via one of the fiddler loopbacks.
Such as http://fiddler.ipv4:11026 ... ...
Details are given here:
http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost
Shows how to set it up and capture traffic. It is the method I've used when I want to see traffic being passed between local web apis and my Mvc project
I've a web job that is trying to send an email when it reads something from the Azure poision q.
public static void ProcessPoisonNotification(
[QueueTrigger("parkingticketnotification-poison")] ParkingTicketNotificationBO notificationBo,
TextWriter log)
{
var message = "xxx xxx xxx xxx xxx => POISON message: " + notificationBo.Dump();
Console.WriteLine(message);
log?.WriteLine(message);
PoisonEmailNotifier.SendFailureMessage(notificationBo);
}
The Email notifier is using code from the main web applicaiton, which can send emails. but the Web job throws the following exception. Is it because the web application is blocking port 25?
The Email notifier is using code from the main web applicaiton, which can send emails. but the Web job throws the following exception.
Base on my experience, as the Web application and WebJob are in the same environment, if it is worked in the Web application, it should be also worked in the Azure WebJob.
If WebJob is worked locally, please have a try to remote debug the WebJob. More details about how to remote debug the webjob, please refer to the tutorials.
Note: Click the Settings tab, and change Configuration to Debug, before it is published.
Besides,we also can use Azure SendGrid to send email easily.
That looks like Windows Socket Error Code 10013. You can find out more about it here.
Microsoft has two suggestions - you likely either have insufficient permissions or another service is bound to the target port. If you know that traffic on port 25 is not open on your host, it seems likely that this is the cause. However, you may instead have some other service listening to that port.
I have a WCF Service hosted and the client is hosted on the same server. I try to show some error message via a dialog box. its working as expected when i try to perform some action which throws that error in server but its showing Bad request when i try to work on Local machine.
Can't post the configuration file. Client machine So :) . Hosting is IIS
I found that in the controllers catch block where i am calling the wcf service whenever we are having an exception we are setting
Respose.StatusCode = (int)HttpStatusCode.BadRequest;
return Json(execption.Message);
Does this have anything to do ?
I added this setting in the web config and i am able to see the actual message in my local machine too
<httpErrors existingResponse="PassThrough" />
Is there any other way of doing it from coding part
I have created a new WorkerRole using the template for a QueueWorkerRole in VS 2013 and it creates code that looks like this:
// Create the queue if it does not exist already
var connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.QueueExists(QueueName))
{
namespaceManager.CreateQueue(QueueName);
}
// Initialize the connection to Service Bus Queue
_client = QueueClient.CreateFromConnectionString(connectionString, QueueName);
The problem I ma having is setting the Microsoft.ServiceBus.ConnectionString correctly so that it will work with my local development queues running in the emulator. By default it sets it up like this:
<appSettings>
<!-- Service Bus specific app setings for messaging connections -->
<add key="Microsoft.ServiceBus.ConnectionString" value="Endpoint=sb://[your namespace].servicebus.windows.net;SharedSecretIssuer=owner;SharedSecretValue=[your secret]" />
</appSettings>
And I'm guessing this will work fine when I have a hosted service to connect to but I am just trying out some things locally and can't get it to connect.
I have tried "UseDevelopmentStorage=True" and I've tried using the address I found when viewing the Storage Emulator UI "127.0.0.1:10001" as well as the Local Emulator using Standard Format I found here: http://www.connectionstrings.com/windows-azure/ (DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;
AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;) but I am having no luck.
Sometimes I am seeing "The Service Bus connection string contains invalid property" in the Compute Emulator UI and other times I get an error that it can't connect.
Thanks.
The problem you are having here is that you are attempting to plug a queue connection string into a Service Bus Connection String Creator. Those two connection strings are inherently different.
To use development storage you need to set the value of the app setting key you wish to use to: "UseDevelopmentStorage=true" as seen in this stack overflow:
Windows Azure Storage Emulator Connection String for ASP.NET MVC? This will work for STORAGE (not service bus)