Quantcast
Channel: Service Bus forum
Viewing all articles
Browse latest Browse all 1916

Can't get the ConnectionStatusBehavior to work

$
0
0

Hello,

I'm registering a WCF service endpoint on the Windows Azure Service Bus using the NetTcpRelayBinding.

Now I want to monitor the connection state to the Windows Azure Service Bus with help of the Microsoft.ServiceBus.ConnectionStatusBehavior [1]. Based on the description in the "Remarks"-section I expected to receive events every time the connection is lost and reestablished - i.e. the Connecting-Event when the connection was lost and the channels trying to reconnect and the Online-Event after successfully reestablishing the connection.

The problem: I only receive the Online-Event once after a connection to the Service Bus has been established for the first time. After that I only receive the Connecting-Event every time the connection is lost (I disabled the network adapter to cause the disconnect).

Hopefully someone with more knowledge can point me in the right direction!

I use the following code to (programmatically) set up the ServiceHost:

class Program
{
    const string Namespace = "**********";

    const string SharedAccessKeyName = "RootManageSharedAccessKey";
    const string SharedAccessKey = "**********";

    static readonly TokenProvider TokenProvider =
        TokenProvider.CreateSharedAccessSignatureTokenProvider(SharedAccessKeyName, SharedAccessKey);


    static void Main()
    {
        var sh = new ServiceHost(typeof(MessageService));
        sh.Faulted += (s, e) => Console.WriteLine("ServiceHost faulted");


        // add service endpoint
        var address = ServiceBusEnvironment.CreateServiceUri("sb", Namespace, "servicepath123");
        var binding = new NetTcpRelayBinding(EndToEndSecurityMode.Transport, RelayClientAuthenticationType.None);
        var endpoint = sh.AddServiceEndpoint(typeof(IMessageService), binding, address);

        // add endpoint behaviors
        endpoint.Behaviors.Add(new TransportClientEndpointBehavior(TokenProvider));

        var connectionStatusBehavior = new ConnectionStatusBehavior();
        connectionStatusBehavior.Connecting += (s, e) => Console.WriteLine("Connecting");
        connectionStatusBehavior.Online += (s, e) => Console.WriteLine("Online");
        connectionStatusBehavior.Offline += (s, e) => Console.WriteLine("Offline");
        endpoint.Behaviors.Add(connectionStatusBehavior);


        sh.Open();

        Console.WriteLine("Press ENTER to close");
        Console.ReadLine();

        sh.Close();
    }
}


Viewing all articles
Browse latest Browse all 1916

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>