更新 : 2007 年 11 月
サービスまたはクライアント アプリケーションでの通信エラーを表します。
名前空間 :
System.ServiceModel
アセンブリ :
System.ServiceModel (System.ServiceModel.dll 内)
<SerializableAttribute> _
Public Class CommunicationException _
Inherits SystemException
Dim instance As CommunicationException
[SerializableAttribute]
public class CommunicationException : SystemException
[SerializableAttribute]
public ref class CommunicationException : public SystemException
/** @attribute SerializableAttribute */
public class CommunicationException extends SystemException
public class CommunicationException extends SystemException
堅牢なクライアントとサービスを提供する Windows Communication Foundation (WCF) アプリケーションは、通信中にスローされる可能性がある CommunicationException オブジェクトを処理します。さらに、CommunicationException から派生する 2 種類の例外 (FaultException<(Of <(TDetail>)>) と FaultException) があり、これらはクライアントでも発生することがあります。したがって、ジェネリックな CommunicationException ハンドラでより限定された種類の例外をキャッチすることを避けるために、CommunicationException を処理する前にこれらの例外をキャッチします。
FaultException オブジェクトは、リスナが予想外の SOAP エラーを受信した場合、または操作コントラクト内に指定されていない SOAP エラーを受信した場合にスローされます。通常、これは、アプリケーションのデバッグ中に、サービスの IncludeExceptionDetailInFaults プロパティに true が設定されている場合に発生します。
メモ : |
|---|
カスタム チャネルとバインディング要素を実装するときは、作成するコンポーネントで System..::.TimeoutException または CommunicationException の派生オブジェクトだけがスローされることを強くお勧めします。コンポーネントが、コンポーネントに固有の回復可能例外をスローする場合は、その例外を CommunicationException オブジェクトの中にラップしてください。 |
WCF エラー システムの設計および使用の詳細については、「コントラクトおよびサービスのエラーの指定と処理」を参照してください。
次のコード例では、CommunicationException を処理するクライアントを示します。このクライアントは、サービスの IncludeExceptionDetailInFaults が true に設定されているため、FaultException オブジェクトも処理します。
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
参照