3

我已经开始研究 Windows 1.0 的服务总线,以便为我们的应用程序创建本地服务总线,并且我按照此处显示的示例首次尝试使用该总线:http: //msdn.microsoft.com/en-us/库/windowsazure/jj542433(v=azure.10).aspx

但是,当我运行示例时,我收到以下错误:

访问“https://{machineName.domainName}/ServiceBusDefaultNamespace/$STS/Windows/”时,令牌提供程序无法提供安全令牌。令牌提供程序返回消息:“底层连接已关闭:发送时发生意外错误。”

内部例外:

底层连接已关闭:发送时发生意外错误。

我搜索的所有内容都与本地生成的证书等问题有关。不是那样的。使用“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();
        }
    }
}
4

0 回答 0