I'm following this tutorial, and I keep getting an exception calling QueueClient.Send().
First off, here's my connection string setting in the App.Config (with {computername} replaced by the actual machine name):
<add key="Microsoft.ServiceBus.ConnectionString" value="Endpoint=sb://{computername}/ServiceBusDefaultNamespace;StsEndpoint=https://{computername}:9355/ServiceBusDefaultNamespace;RuntimePort=9354;ManagementPort=9355" />
Here's the code I'm running:
NamespaceManager namespaceManager = NamespaceManager.Create();
TokenProvider nameSpaceManagerTokenProvider = TokenProvider.CreateWindowsTokenProvider(
new List<Uri>() { namespaceManager.Address }, new NetworkCredential(user, password));
TokenProvider messagingToken = TokenProvider.CreateWindowsTokenProvider(
new List<Uri>() { namespaceManager.Address }, new NetworkCredential(user, password));
namespaceManager.Settings.TokenProvider = nameSpaceManagerTokenProvider;
MessagingFactorySettings messageFactorySettings = new MessagingFactorySettings {TokenProvider = messagingToken};
MessagingFactory messagingFactory = MessagingFactory.Create(namespaceManager.Address, messageFactorySettings);
if (namespaceManager.QueueExists(QueueName))
{
namespaceManager.DeleteQueue(QueueName);
}
QueueDescription qd = new QueueDescription(QueueName);
namespaceManager.CreateQueue(qd);
QueueClient myQueueClient = messagingFactory.CreateQueueClient(QueueName);
BrokeredMessage sendMessage = new BrokeredMessage("Hello, World!");
myQueueClient.Send(sendMessage); // <---- This is where I'm getting the exception
The queue is deleted/created without a problem. Calling the .Send() method gives me the following error:
Microsoft.ServiceBus.Messaging.MessagingCommunicationException
"The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.9579976'."
The inner exception is simply "An existing connection was forcibly closed by the remote host"
Here's the stack trace:
at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.EndSendCommand(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.OnEndSend(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.OnSend(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout)
at Microsoft.ServiceBus.Messaging.MessageSender.Send(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout)
at Microsoft.ServiceBus.Messaging.MessageSender.Send(BrokeredMessage message)
at Microsoft.ServiceBus.Messaging.QueueClient.Send(BrokeredMessage message)
at SBDemo.Program.Main(String[] args) in c:\Users\hartez\Documents\bitbucket\SBDemo\SBDemo\Program.cs:line 51
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I'm currently running both the client code and the Service Bus on a Windows 7 64-bit dev box. I originally ran Service Bus on a 2012 Server machine and had the same problem.
The problem occurs with both the WindowsTokenProvider and the OauthTokenProvider. The user account is an administrator (in hopes that this was just a permissions issue); that doesn't seem to help. I've also tried this with the Windows Firewall deactivated, but that didn't help, either.
I enabled the Analytic and Debug logs in the Event Viewer, but I'm not seeing an anything in those logs to suggest what the problem might be.
If anyone has any suggestions on what might be wrong, or on other ways to debug this, I'd very much appreciate it.
Glad you have figured this out.
MessagingFactory messagingFactory = MessagingFactory.Create(namespaceManager.Address, messageFactorySettings);
The issue you had in your original code is that it is using the NamespaceManager address for the MessagingFactory. The MessagingFactory uses a different port than the NamespaceManager.
NamespaceManager is used for management (CRUD) operations and SB has a management endpoint for it.
MessagingFactory is used for runtime operations (Send/Receive/..) and SB has a runtime endoiunt for it.
QueueClient.Create(QueueName) internally creates a messaging factory and uses the default address and port for runtime operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With