我正在学习本教程,但我不断收到异常调用QueueClient.Send()
。
首先,这是我在 App.Config 中的连接字符串设置(将 {computername} 替换为实际机器名称):
<add key="Microsoft.ServiceBus.ConnectionString" value="Endpoint=sb://{computername}/ServiceBusDefaultNamespace;StsEndpoint=https://{computername}:9355/ServiceBusDefaultNamespace;RuntimePort=9354;ManagementPort=9355" />
这是我正在运行的代码:
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
队列被删除/创建没有问题。调用该.Send()
方法会给我以下错误:
Microsoft.ServiceBus.Messaging.MessagingCommunicationException
“套接字连接已中止。这可能是由于处理您的消息时出错或远程主机超出接收超时,或底层网络资源问题造成的。本地套接字超时为 '00:00:59.9579976'。”
内部异常只是“现有连接被远程主机强行关闭”
这是堆栈跟踪:
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()
我目前在 Windows 7 64 位开发盒上运行客户端代码和服务总线。我最初在 2012 Server 机器上运行 Service Bus 并且遇到了同样的问题。
WindowsTokenProvider
和都会出现问题OauthTokenProvider
。用户帐户是管理员(希望这只是权限问题);这似乎没有帮助。我也尝试过禁用 Windows 防火墙,但这也无济于事。
我在事件查看器中启用了分析和调试日志,但我没有在这些日志中看到任何提示问题可能的内容。
如果有人对可能出现的问题或其他调试方法有任何建议,我将不胜感激。