System.ServiceModel 名前空間


.NET Framework クラス ライブラリ
CommunicationException クラス

更新 : 2007 年 11 月

サービスまたはクライアント アプリケーションでの通信エラーを表します。

名前空間 :  System.ServiceModel
アセンブリ :  System.ServiceModel (System.ServiceModel.dll 内)
構文

Visual Basic (宣言)
<SerializableAttribute> _
Public Class CommunicationException _
    Inherits SystemException
Visual Basic (使用法)
Dim instance As CommunicationException
C#
[SerializableAttribute]
public class CommunicationException : SystemException
Visual C++
[SerializableAttribute]
public ref class CommunicationException : public SystemException
J#
/** @attribute SerializableAttribute */ 
public class CommunicationException extends SystemException
JScript
public class CommunicationException extends SystemException
解説

堅牢なクライアントとサービスを提供する Windows Communication Foundation (WCF) アプリケーションは、通信中にスローされる可能性がある CommunicationException オブジェクトを処理します。さらに、CommunicationException から派生する 2 種類の例外 (FaultException<(Of <(TDetail>)>)FaultException) があり、これらはクライアントでも発生することがあります。したがって、ジェネリックな CommunicationException ハンドラでより限定された種類の例外をキャッチすることを避けるために、CommunicationException を処理する前にこれらの例外をキャッチします。

  • FaultException<(Of <(TDetail>)>) オブジェクトは、操作コントラクト内に指定された SOAP エラーが、双方向操作 (つまり、IsOneWayfalse が設定されている OperationContractAttribute 属性を持つメソッド) への応答で受信された場合に、クライアント上でスローされます。

FaultException オブジェクトは、リスナが予想外の SOAP エラーを受信した場合、または操作コントラクト内に指定されていない SOAP エラーを受信した場合にスローされます。通常、これは、アプリケーションのデバッグ中に、サービスの IncludeExceptionDetailInFaults プロパティに true が設定されている場合に発生します。

ms405965.alert_note(ja-jp,VS.90).gifメモ :

カスタム チャネルとバインディング要素を実装するときは、作成するコンポーネントで System..::.TimeoutException または CommunicationException の派生オブジェクトだけがスローされることを強くお勧めします。コンポーネントが、コンポーネントに固有の回復可能例外をスローする場合は、その例外を CommunicationException オブジェクトの中にラップしてください。

WCF エラー システムの設計および使用の詳細については、「コントラクトおよびサービスのエラーの指定と処理」を参照してください。


次のコード例では、CommunicationException を処理するクライアントを示します。このクライアントは、サービスの IncludeExceptionDetailInFaultstrue に設定されているため、FaultException オブジェクトも処理します。

C#
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using Microsoft.WCF.Documentation;

public class Client
{
  public static void Main()
  {
    // Picks up configuration from the configuration file.
    SampleServiceClient wcfClient = new SampleServiceClient();
    try
    {
      // Making calls.
      Console.WriteLine("Enter the greeting to send: ");
      string greeting = Console.ReadLine();
      Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting));
      Console.WriteLine("Press ENTER to exit:");
      Console.ReadLine();
    }
    catch (TimeoutException timeProblem)
    {
      Console.WriteLine("The service operation timed out. " + timeProblem.Message);
      wcfClient.Abort();
      Console.ReadLine();
    }
    // Catch the contractually specified SOAP fault raised here as an exception.
    catch (FaultException<GreetingFault> greetingFault)
    {
      Console.WriteLine(greetingFault.Detail.Message);
      Console.Read();
      wcfClient.Abort();
    }
    // Catch unrecognized faults. This handler receives exceptions thrown by WCF
    // services when ServiceDebugBehavior.IncludeExceptionDetailInFaults 
    // is set to true.
    catch (FaultException faultEx)
    {
      Console.WriteLine("An unknown exception was received. " 
        + faultEx.Message
        + faultEx.StackTrace
      );
      Console.Read();
      wcfClient.Abort();
    }
    // Standard communication fault handler.
    catch (CommunicationException commProblem)
    {
      Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace);
      Console.Read();
      wcfClient.Abort();
    }
  }
}
継承階層

System..::.Object
  System..::.Exception
    System..::.SystemException
      System.ServiceModel..::.CommunicationException
        System.ServiceModel..::.ActionNotSupportedException
        System.ServiceModel..::.AddressAccessDeniedException
        System.ServiceModel..::.AddressAlreadyInUseException
        System.ServiceModel..::.ChannelTerminatedException
        System.ServiceModel..::.CommunicationObjectAbortedException
        System.ServiceModel..::.CommunicationObjectFaultedException
        System.ServiceModel.Dispatcher..::.MessageFilterException
        System.ServiceModel..::.EndpointNotFoundException
        System.ServiceModel..::.FaultException
        System.ServiceModel.Persistence..::.PersistenceException
        System.ServiceModel..::.PoisonMessageException
        System.ServiceModel..::.ProtocolException
        System.ServiceModel.Security..::.MessageSecurityException
        System.ServiceModel.Security..::.SecurityAccessDeniedException
        System.ServiceModel.Security..::.SecurityNegotiationException
        System.ServiceModel..::.ServerTooBusyException
        System.ServiceModel..::.ServiceActivationException
スレッド セーフ

この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム

Windows Vista, Windows XP SP2, Windows Server 2003, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
バージョン情報

.NET Framework

サポート対象 : 3.5、3.0

.NET Compact Framework

サポート対象 : 3.5
参照

参照

タグ :


Page view tracker