From: Atsushi Eno Date: Fri, 26 Mar 2010 14:50:46 +0000 (-0000) Subject: 2010-03-26 Atsushi Enomoto X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=cb9aee8dda84defe6afdf348c21067b79da8998a;p=mono.git 2010-03-26 Atsushi Enomoto * FaultConverter.cs : do implement OnTryCreateFaultMessage() to work with certain Exception types. svn path=/trunk/mcs/; revision=154281 --- diff --git a/mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog b/mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog index 1f834ff1183..df2d98e34b3 100755 --- a/mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog +++ b/mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog @@ -1,3 +1,8 @@ +2010-03-26 Atsushi Enomoto + + * FaultConverter.cs : do implement OnTryCreateFaultMessage() to work + with certain Exception types. + 2010-03-26 Atsushi Enomoto * Message.cs : fix explanation on CreateMessage() overloads. diff --git a/mcs/class/System.ServiceModel/System.ServiceModel.Channels/FaultConverter.cs b/mcs/class/System.ServiceModel/System.ServiceModel.Channels/FaultConverter.cs index ef383290328..116e6c797f0 100644 --- a/mcs/class/System.ServiceModel/System.ServiceModel.Channels/FaultConverter.cs +++ b/mcs/class/System.ServiceModel/System.ServiceModel.Channels/FaultConverter.cs @@ -62,57 +62,66 @@ namespace System.ServiceModel.Channels { return OnTryCreateFaultMessage (error, out message); } + } - Message CreateSimpleFaultMessage (Exception error, MessageVersion version) + class SimpleFaultConverter : FaultConverter + { + static readonly Dictionary map; + + static SimpleFaultConverter () { - OperationContext ctx = OperationContext.Current; - // FIXME: support more fault code depending on the exception type. - FaultCode fc = null; - if (error is EndpointNotFoundException) - fc = new FaultCode ( - "DestinationUnreachable", - version.Addressing.Namespace); - else - fc = new FaultCode ( - "FIXME_InternalError", - version.Addressing.Namespace); + map = new Dictionary (); + map [typeof (EndpointNotFoundException)] = "DestinationUnreachable"; + map [typeof (ActionNotSupportedException)] = "ActionNotSupported"; + } -#if !NET_2_1 - // FIXME: set correct fault reason. - if (ctx.EndpointDispatcher.ChannelDispatcher.IncludeExceptionDetailInFaults) { - ExceptionDetail detail = new ExceptionDetail (error); - return Message.CreateMessage (version, fc, - "error occured", detail, ctx.IncomingMessageHeaders != null ? ctx.IncomingMessageHeaders.Action : null); - } -#endif - return Message.CreateMessage (version, fc, "error occured", ctx.IncomingMessageHeaders.Action); + MessageVersion version; + + public SimpleFaultConverter (MessageVersion version) + { + this.version = version; } - class SimpleFaultConverter : FaultConverter + protected override bool OnTryCreateException ( + Message message, MessageFault fault, out Exception error) { - MessageVersion version; - public SimpleFaultConverter (MessageVersion version) - { - this.version = version; - } + error = null; + return false; + } - protected override bool OnTryCreateException ( - Message message, MessageFault fault, out Exception error) - { - error = null; + protected override bool OnTryCreateFaultMessage (Exception error, out Message message) + { + if (version.Addressing.Equals (AddressingVersion.None)) { + message = null; return false; } - protected override bool OnTryCreateFaultMessage ( - Exception error, out Message message) - { + string action; + if (!map.TryGetValue (error.GetType (), out action)) { message = null; - if (OperationContext.Current == null) - return false; + return false; + } - message = CreateSimpleFaultMessage (error, version); - return true; + FaultCode fc; + if (version.Envelope.Equals (EnvelopeVersion.Soap12)) + fc = new FaultCode ("Sender", version.Envelope.Namespace, new FaultCode (action, version.Addressing.Namespace)); + else + fc = new FaultCode (action, version.Addressing.Namespace); + + OperationContext ctx = OperationContext.Current; + // FIXME: support more fault code depending on the exception type. +#if !NET_2_1 + // FIXME: set correct fault reason. + if (ctx != null && ctx.EndpointDispatcher.ChannelDispatcher.IncludeExceptionDetailInFaults) { + ExceptionDetail detail = new ExceptionDetail (error); + message = Message.CreateMessage (version, fc, + error.Message, detail, version.Addressing.FaultNamespace); } +#endif + else + message = Message.CreateMessage (version, fc, error.Message, version.Addressing.FaultNamespace); + + return true; } } }