クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework 3.5
System.ServiceModel 名前空間
CommunicationException クラス

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.Net Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.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();
    }
  }
}

この型のすべてのパブリック 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
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker