0

我正在使用中继绑定来创建 ChannelListener。

BasicHttpRelayBinding relayBinding = new BasicHttpRelayBinding();
relayBinding.BuildChannelListener<IReplyChannel>(..., ...);

现在我想添加 ConnectionStatusBehavior 以便我知道频道使用的连接是否在线。有谁知道如何做到这一点?

4

1 回答 1

3

这是我们的做法

ConnectionStatusBehavior connectionStatus = new ConnectionStatusBehavior();
connectionStatus.Connecting += (s, e) => Logger.Info(System.DateTime.Now.TimeOfDay + " ConnectionStatus: Connecting, IsOnline: " + connectionStatus.IsOnline);
connectionStatus.Offline += (s, e) =>
{
   Logger.Info(System.DateTime.Now.TimeOfDay + " ConnectionStatus: Offline");
   if (connectionStatus.LastError != null)
   {
     connectionStatus.Retry();
     Logger.Debug(connectionStatus.LastError.ToString());
   }
};

connectionStatus.Online += (s, e) => Logger.Info(System.DateTime.Now.TimeOfDay + " ConnectionStatus: Online");

foreach (ServiceEndpoint endpoint in _serviceHost.Description.Endpoints)
{
  if (endpoint.Address.Uri.AbsoluteUri.StartsWith("sb:"))
  {
    endpoint.Behaviors.Add(connectionStatus);
  }
}
于 2013-09-20T14:19:09.577 回答