【WCF】【C#】WCF ~ 状態編 ~

■ はじめに

 * CommunicationObject.State プロパティで、状態を知ることが可能。

参考文献

http://msdn.microsoft.com/ja-jp/library/ms789041.aspx
http://msdn.microsoft.com/ja-jp/library/system.servicemodel.communicationstate(v=vs.85).aspx

■ Faulted

 * 回復不能なエラーや障害が発生し、使用できない状態になっていることを示す

対処

 * Fault 状態にあるオブジェクトは、Abort メソッドを使用して閉じる必要がある

例外のハンドリング

ChannelFactory<ISampleService> sampleServiceFactory = null;

ISampleService client = sampleServiceFactory.CreateChannel();
sampleServiceFactory.Faulted+= new EventHandler(ProxyServiceFactoryOnFaulted);

private void ProxyServiceFactoryOnFaulted(object sender, EventArgs e)
{
    (sender as ISampleService ).Abort();
    if (sender is ISampleService)
    {
         sender = this.sampleServiceFactory.CreateChannel();
    }
}


関連記事

WCF

WCF ~ 基礎知識編 ~
https://blogs.yahoo.co.jp/dk521123/22254537.html