title: Service Bus for Windows 1.0 error
body: <p>I've started investigating the Service Bus for Windows 1.0 to create a local Service Bus for our applications and I followed the example shown here for my first attempt at using the bus:  <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj542433(v=azure.10).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windowsazure/jj542433(v=azure.10).aspx</a></p>
  
  <p>However, when I run the sample I receive the following error(s):</p>
  
  <blockquote>
    <p>The token provider was unable to provide a security token while
    accessing
    'https://{machineName.domainName}/ServiceBusDefaultNamespace/$STS/Windows/'.
    Token provider returned message: 'The underlying connection was
    closed: An unexpected error occurred on a send.'</p>
  </blockquote>
  
  <p>with an inner exception of:</p>
  
  <blockquote>
    <p>The underlying connection was closed: An unexpected error occurred on a send.</p>
  </blockquote>
  
  <p>Everything that I have searched on relates to problems around the locally generated certificate, etc. This isn't that. Browsing to the STS using 'https://{machineName.domainName}:9355/ServiceBusDefaultNamespace/' returns an atom feed of queues/topics. Any help moving this forward to get at least the sample working?</p>
  
  <p>Source code (99% identical to sample link above; only stylistic differences and ServerFQDN address, which is local and matches the data from installation):</p>
  
  <pre><code>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&lt;string&gt;() );
                      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();
          }
      }
  }
  </code></pre>