2010-03-26 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 26 Mar 2010 14:50:46 +0000 (14:50 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 26 Mar 2010 14:50:46 +0000 (14:50 -0000)
* FaultConverter.cs : do implement OnTryCreateFaultMessage() to work
  with certain Exception types.

svn path=/trunk/mcs/; revision=154281

mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
mcs/class/System.ServiceModel/System.ServiceModel.Channels/FaultConverter.cs

index 1f834ff11835bcc3139eed8434c4becc283b014e..df2d98e34b3ecf752e64522376d1d8a3990de944 100755 (executable)
@@ -1,3 +1,8 @@
+2010-03-26  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * FaultConverter.cs : do implement OnTryCreateFaultMessage() to work
+         with certain Exception types.
+
 2010-03-26  Atsushi Enomoto  <atsushi@ximian.com>
 
        * Message.cs : fix explanation on CreateMessage() overloads.
index ef383290328b77c80c85f829902beec3b5d6dfec..116e6c797f0ca472fc212b34150dae45aae65d0e 100644 (file)
@@ -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<Type,string> 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<Type,string> ();
+                       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;
                }
        }
 }