CommunicationException クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
サービス またはクライアント アプリケーションの通信エラーを表します。
public ref class CommunicationException : Exception
public ref class CommunicationException : SystemException
public class CommunicationException : Exception
[System.Serializable]
public class CommunicationException : SystemException
type CommunicationException = class
inherit Exception
[<System.Serializable>]
type CommunicationException = class
inherit SystemException
Public Class CommunicationException
Inherits Exception
Public Class CommunicationException
Inherits SystemException
- 継承
- 継承
- 派生
- 属性
例
次のコード例は、 CommunicationException 型を処理するクライアントを示しています。 このクライアントは、サービスFaultExceptionIncludeExceptionDetailInFaultsに設定されているため、trueオブジェクトも処理します。
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();
}
}
}
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports Microsoft.WCF.Documentation
Public Class Client
Public Shared Sub Main()
' Picks up configuration from the configuration file.
Dim wcfClient As New SampleServiceClient()
Try
' Making calls.
Console.WriteLine("Enter the greeting to send: ")
Dim greeting As String = Console.ReadLine()
Console.WriteLine("The service responded: " & wcfClient.SampleMethod(greeting))
Console.WriteLine("Press ENTER to exit:")
Console.ReadLine()
Catch timeProblem As TimeoutException
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 greetingFault As FaultException(Of 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 faultEx As FaultException
Console.WriteLine("An unknown exception was received. " & faultEx.Message + faultEx.StackTrace)
Console.Read()
wcfClient.Abort()
' Standard communication fault handler.
Catch commProblem As CommunicationException
Console.WriteLine("There was a communication problem. " & commProblem.Message + commProblem.StackTrace)
Console.Read()
wcfClient.Abort()
End Try
End Sub
End Class
注釈
堅牢なクライアントとサービスの Windows Communication Foundation (WCF) アプリケーションは、通信中にスローされる可能性のある CommunicationException オブジェクトを処理します。 また、クライアントが期待する CommunicationException派生例外の種類 (FaultException<TDetail> と FaultException) も 2 つあります。 そのため、ジェネリック CommunicationException ハンドラーがこれらのより具体的な例外の種類をキャッチしないようにするには、 CommunicationExceptionを処理する前にこれらの例外をキャッチします。
-
FaultException<TDetail>オブジェクトは、操作コントラクトで指定された SOAP エラーが双方向操作 (つまり、OperationContractAttributeが IsOneWay に設定された
false属性を持つメソッド) に応答して受信されると、クライアントでスローされます。
FaultException オブジェクトは、予期されていない SOAP エラーまたは操作コントラクトで指定された SOAP エラーをリスナーが受信するとスローされます。 これは通常、アプリケーションがデバッグ中で、サービスに IncludeExceptionDetailInFaults プロパティが true に設定されている場合に発生します。
Note
カスタム チャネルとバインド要素を実装する場合は、コンポーネントが System.TimeoutException または CommunicationException派生オブジェクトのみをスローすることを強くお勧めします。 コンポーネントがコンポーネントに固有の回復可能な例外をスローする場合は、その例外を CommunicationException オブジェクト内でラップします。
WCF 障害システムの設計と使用の詳細については、「 コントラクトとサービスでのエラーの指定と処理」を参照してください。
Important
WCF ランタイムは、WCF ランタイムを離れ、ユーザー コードを入力した時点で処理するのが安全でない CommunicationException をスローしません。
コンストラクター
| 名前 | 説明 |
|---|---|
| CommunicationException() |
CommunicationException クラスの新しいインスタンスを初期化します。 |
| CommunicationException(SerializationInfo, StreamingContext) |
指定したシリアル化情報とコンテキスト オブジェクトを使用して、 CommunicationException クラスの新しいインスタンスを初期化します。 |
| CommunicationException(String, Exception) |
指定したメッセージと内部例外を使用して、 CommunicationException クラスの新しいインスタンスを初期化します。 |
| CommunicationException(String) |
指定したメッセージを使用して、 CommunicationException クラスの新しいインスタンスを初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| Data |
例外に関する追加のユーザー定義情報を提供するキーと値のペアのコレクションを取得します。 (継承元 Exception) |
| HelpLink |
この例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。 (継承元 Exception) |
| HResult |
特定の例外に割り当てられるコード化された数値である HRESULT を取得または設定します。 (継承元 Exception) |
| InnerException |
現在の例外の原因となった Exception インスタンスを取得します。 (継承元 Exception) |
| Message |
現在の例外を説明するメッセージを取得します。 (継承元 Exception) |
| Source |
エラーの原因となるアプリケーションまたはオブジェクトの名前を取得または設定します。 (継承元 Exception) |
| StackTrace |
呼び出し履歴のイミディエイト フレームの文字列表現を取得します。 (継承元 Exception) |
| TargetSite |
現在の例外をスローするメソッドを取得します。 (継承元 Exception) |
メソッド
| 名前 | 説明 |
|---|---|
| Equals(Object) |
指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| GetBaseException() |
派生クラスでオーバーライドされた場合、1 つ以上の後続の例外の根本原因である Exception を返します。 (継承元 Exception) |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
派生クラスでオーバーライドされた場合は、例外に関する情報を使用して SerializationInfo を設定します。 (継承元 Exception) |
| GetType() |
現在のインスタンスのランタイム型を取得します。 (継承元 Exception) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| ToString() |
現在の例外の文字列形式を作成して返します。 (継承元 Exception) |
イベント
| 名前 | 説明 |
|---|---|
| SerializeObjectState |
例外に関するシリアル化されたデータを含む例外状態オブジェクトを作成するために例外がシリアル化されるときに発生します。 (継承元 Exception) |