私は単純な WCF HTTP/SOAP Web サービスを持っています。サービスの実装は次のようになります。
public CustomResponse DoSomething(CustomRequest request)
{
try
{
return InternalGubbins.WithErrorHandling.ProcessRequest(request);
}
catch
{
// Some sort of error occurred that is not gracefully
// handled elsewhere in the framework
throw new SoapException("Hmmm, it would seem that the cogs are meshed!", SoapException.ServerFaultCode);
}
}
ここで、その SoapException がスローされた場合Hmmm, it would seem that the cogs are meshed!
、追加の例外の詳細 (つまりスタック トレース) なしで、呼び出し元のクライアントに例外メッセージ (つまり ) が返されるようにします。
true (サーバー上の web.config)に設定includeExceptionDetailInFaults
すると、スタック トレースなどを含む完全な例外がクライアントに返されます。ただし、false に設定すると、一般的なメッセージが表示されます。
内部エラーのため、サーバーは要求を処理できませんでした。エラーの詳細については、サーバーで (ServiceBehaviorAttribute または構成動作のいずれかから) IncludeExceptionDetailInFaults をオンにして、例外情報をクライアントに送り返すか、Microsoft .NET Framework 3.0 SDK ドキュメントに従ってトレースをオンにします。サーバーのトレース ログを調べます。
問題は、SoapException メッセージを呼び出し元のクライアントに戻すにはどうすればよいかということです。すなわち:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault</a:Action>
<a:RelatesTo>urn:uuid:185719f4-6113-4126-b956-7290be375342</a:RelatesTo>
</s:Header>
<s:Body>
<s:Fault>
<s:Code>
<s:Value>s:Receiver</s:Value>
<s:Subcode>
<s:Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</s:Value>
</s:Subcode>
</s:Code>
<s:Reason>
<s:Text xml:lang="en-GB">Hmmm, it would seem that the cogs are meshed!</s:Text>
</s:Reason>
</s:Fault>
</s:Body>
</s:Envelope>