我已经开始调查Windows 1.0 Service Bus,为我们的应用程序创建一个本地服务总线,我按照这里显示的示例首次尝试使用总线:http://msdn.microsoft.com/en-us/library/windowsazure/jj542433(v=azure.10).aspx
但是,当我运行示例时,我收到以下错误:
令牌提供程序无法提供安全令牌 访问 的 'https:// {} machineName.domainName / ServiceBusDefaultNamespace / $ STS /窗/'。 令牌提供程序返回消息:'基础连接是 已关闭:发送时发生意外错误。'
内部例外:
基础连接已关闭:发送时发生意外错误。
我搜索过的所有内容都与本地生成的证书等问题有关。这不是那个问题。使用“https:// {machineName.domainName}:9355 / ServiceBusDefaultNamespace /”浏览STS会返回队列/主题的原子提要。是否有任何帮助推动这项工作至少取样?
源代码(99%与上面的示例链接相同;只有样式差异和ServerFQDN地址,这是本地的并且与安装中的数据相匹配):
using System;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
namespace ServiceBus1
{
class Program
{
private const string ServerFQDN = "{machineName}.{domain}.net";
private const int HttpPort = 9355;
private const int TcpPort = 9354;
private const string ServiceNamespace = "ServiceBusDefaultNamespace";
static void Main( string[] args )
{
var connBuilder = new ServiceBusConnectionStringBuilder
{
ManagementPort = HttpPort,
RuntimePort = TcpPort
};
connBuilder.Endpoints.Add( new UriBuilder { Scheme = "sb", Host = ServerFQDN, Path = ServiceNamespace }.Uri );
connBuilder.StsEndpoints.Add( new UriBuilder { Scheme = "https", Host = ServerFQDN, Path = ServiceNamespace }.Uri );
var messageFactory = MessagingFactory.CreateFromConnectionString( connBuilder.ToString() );
var namespaceManager = NamespaceManager.CreateFromConnectionString( connBuilder.ToString() );
const string queueName = "ServiceBusQueueSample";
if ( namespaceManager == null )
{
Console.WriteLine( "\nUnexpectedError: NamespaceManager is NULL" );
return;
}
if ( namespaceManager.QueueExists( queueName ) )
{
namespaceManager.DeleteQueue( queueName );
}
namespaceManager.CreateQueue( queueName );
var myQueueClient = messageFactory.CreateQueueClient( queueName );
try
{
// send a message to the queue
var sendMessage = new BrokeredMessage( "Hello World!" );
myQueueClient.Send( sendMessage );
// receive the message from the queue
var receivedMessage = myQueueClient.Receive( TimeSpan.FromSeconds( 5 ) );
if ( receivedMessage != null )
{
Console.WriteLine( "Message received: Body = {0}", receivedMessage.GetBody<string>() );
receivedMessage.Complete(); // releases msg lock and removes from queue?
}
}
catch ( Exception e )
{
Console.WriteLine( "Unexpected exception {0}", e );
}
finally
{
if ( messageFactory != null )
{
messageFactory.Close();
}
}
Console.WriteLine( "Press ENTER to clean up and exit." );
Console.ReadLine();
}
}
}