0

問題

私はこの奇妙な問題を抱えています。コンソール アプリで WCF サーバーをホストしています: Console.WriteLine("Press 'q' to quit.");

            var serviceHost = new ServiceHost(typeof(MessageService));
            serviceHost.Open();
            while (Console.ReadKey().KeyChar != 'q')
            {
            }
            serviceHost.Close();

パブリッシュとサブスクライブ (二重バインディング) の 2 つのエンドポイントを公開します。コンソール アプリを停止または終了すると、クライアント エンドでチャネル エラーが発生しません。サーバーがダウンしていることをクライアントに通知したいと思います。ここで何がうまくいかないのですか?

私が欲しいのは、コンソールアプリがダウンしたときに次のイベントのいずれかが発生することだけです:

    msgsvc.InnerDuplexChannel.Faulted += InnerDuplexChannelOnFaulted;
    msgsvc.InnerChannel.Faulted += InnerChannelOnFaulted;
4

3 に答える 3

1

From MSDN: The duplex model does not automatically detect when a service or client closes its channel. So if a service unexpectedly terminates, by default the service will not be notified, or if a client unexpectedly terminates, the service will not be notified. Clients and services can implement their own protocol to notify each other if they so choose.

于 2013-02-28T13:22:42.570 に答える
0

AFAIK tcp チャネルは (永続的な) 接続の問題に非常に反応しますが、コールバックを使用して、サーバーが使用できなくなる前にクライアントに通知できます。クライアント側から、ダミーの ping/poke メソッド「OnTimer」を使用して、実際の接続状態を取得したり、チャネルを維持したりできます。その時点でクライアント プロキシを回復 (再接続) するのが良いと思います。サービスがメタデータ エンドポイントを提供する場合は、試用接続のために svcutil を呼び出すか、プログラムでメタデータを取得することもできます。

  Uri mexAddress = new Uri("http://localhost:5000/myservice");
  var mexClient = new MetadataExchangeClient(mexAddress, MetadataExchangeClientMode.HttpGet);
  MetadataSet metadata = mexClient.GetMetadata();
  MetadataImporter importer = new WsdlImporter(metadata);
  ServiceEndpointCollection endpoints = importer.ImportAllEndpoints();

  ContractDescription description =
  ContractDescription.GetContract(typeof(IMyContract));
  bool contractSupported = endpoints.Any(endpoint =>
  endpoint.Contract.Namespace == description.Namespace &&
  endpoint.Contract.Name == description.Name);

また

ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IMyContract), mexAddress, MetadataExchangeClientMode.HttpGet)
于 2013-02-28T20:56:23.870 に答える