■ 概要
WCF サービス内で発生した例外は、通常、セキュリティの観点から、クライアントに一切渡さず 代わりに FaultException がクライアントに返される。
■ サンプル
WCFサービス側
* サービスメソッドにFaultContractAttributeを追加IWcfSampleService.cs
[ServiceContract] public interface IWcfSampleService { [OperationContract] [FaultContract(typeof(WcfException))] void SampleMethod(); }WcfException.cs
[DataContract] public class WcfException { [DataMember] public string Message { get; set; } }
WCFサービスの呼び出し側
try { // WCFサービス呼び出し } catch (FaultException<WcfException> ex) { // 例外処理 } catch (FaultException ex) { // 例外処理 }
参考文献
http://handcraft.blogsite.org/Memo/Article/Archives/12http://csharper.blog57.fc2.com/blog-entry-73.html
http://tnakamura.hatenablog.com/entry/20090901/wcf_exception