Author: atsushi
Date: 2007-03-07 07:03:37 -0500 (Wed, 07 Mar 2007)
New Revision: 73879

Added:
   trunk/olive/class/System.ServiceModel/System.ServiceModel/ExceptionDetail.cs
Modified:
   trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/FaultConverter.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecurityRequestContext.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcher.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcherBase.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/EndpointDispatcher.cs
   trunk/olive/class/System.ServiceModel/System.ServiceModel.dll.sources
   trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog
Log:
2007-03-07  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * ExceptionDetail.cs : new file.

        * SecurityRequestContext.cs : try to reply fault with the inner
          channel when an error occurred internally.
        * FaultConverter.cs : implemented based on OperationContext (at normal
          state it does not seem to create messages, so I implemented it this
          way).

        * EndpointDispatcher.cs : use ErrorHandlers when error was raised.
          Handle exceptions to make into SOAP Fault, using FaultConverter.
        * ChannelDispatcher.cs : simply get ServiceEndpoint at Attach().
        * ChannelDispatcherBase.cs : removed MonoTODOs.



Modified: trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog
===================================================================
--- trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog 
2007-03-07 09:30:43 UTC (rev 73878)
+++ trunk/olive/class/System.ServiceModel/System.ServiceModel/ChangeLog 
2007-03-07 12:03:37 UTC (rev 73879)
@@ -1,5 +1,9 @@
 2007-03-07  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * ExceptionDetail.cs : new file.
+
+2007-03-07  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * ServiceHostBase.cs :
          moved code for applying behavior to ChannelDispatcher.cs.
 

Added: 
trunk/olive/class/System.ServiceModel/System.ServiceModel/ExceptionDetail.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel/ExceptionDetail.cs    
    2007-03-07 09:30:43 UTC (rev 73878)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel/ExceptionDetail.cs    
    2007-03-07 12:03:37 UTC (rev 73879)
@@ -0,0 +1,90 @@
+//
+// OperationContext.cs
+//
+// Author: Atsushi Enomoto ([EMAIL PROTECTED])
+//
+// Copyright (C) 2005,2007 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Runtime.Serialization;
+using System.ServiceModel.Channels;
+using System.ServiceModel.Dispatcher;
+using System.ServiceModel.Security;
+using System.Threading;
+
+namespace System.ServiceModel
+{
+       [DataContract]
+       public class ExceptionDetail
+       {
+               Exception ex;
+               ExceptionDetail inner;
+
+               public ExceptionDetail (Exception exception)
+               {
+                       if (exception == null)
+                               throw new ArgumentNullException ("exception");
+                       ex = exception;
+                       if (ex.InnerException != null)
+                               inner = new ExceptionDetail (ex.InnerException);
+               }
+
+               [DataMember]
+               public string HelpLink {
+                       get { return null; }
+                       private set { } // dummy
+               }
+
+// FIXME: currently it causes StackOverflow (bug in our S.R.Serialization.dll)
+//             [DataMember]
+               [MonoTODO]
+               public ExceptionDetail InnerException {
+                       get { return inner; }
+                       private set { } // dummy
+               }
+
+               [DataMember]
+               public string Message {
+                       get { return ex.Message; }
+                       private set { } // dummy
+               }
+
+               [DataMember]
+               public string StackTrace {
+                       get { return ex.StackTrace; }
+                       private set { } // dummy
+               }
+
+               [DataMember]
+               public string Type {
+                       get { return null; }
+                       private set { } // dummy
+               }
+
+               public override string ToString ()
+               {
+                       return ex.ToString ();
+               }
+       }
+}

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog    
    2007-03-07 09:30:43 UTC (rev 73878)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog    
    2007-03-07 12:03:37 UTC (rev 73879)
@@ -1,5 +1,13 @@
 2007-03-07  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * SecurityRequestContext.cs : try to reply fault with the inner
+         channel when an error occurred internally.
+       * FaultConverter.cs : implemented based on OperationContext (at normal
+         state it does not seem to create messages, so I implemented it this
+         way).
+
+2007-03-07  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * TransportBindingElement.cs : implemented GetProperty<T>().
        * TransactionFlowBindingElement.cs : on building factory or listener,
          reject channel types that cannot build.

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/FaultConverter.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/FaultConverter.cs
        2007-03-07 09:30:43 UTC (rev 73878)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/FaultConverter.cs
        2007-03-07 12:03:37 UTC (rev 73879)
@@ -27,31 +27,29 @@
 //
 using System;
 using System.Collections.Generic;
-using System.ServiceModel.Channels;
+using System.ServiceModel;
 using System.ServiceModel.Description;
 
 namespace System.ServiceModel.Channels
 {
-       [MonoTODO]
        public abstract class FaultConverter
        {
-               static FaultConverter soap12 = new Soap12FaultConverter ();
-               static FaultConverter soap11 = new Soap11FaultConverter ();
-
                public static FaultConverter GetDefaultFaultConverter 
(MessageVersion version)
                {
                        if (version == null)
                                throw new ArgumentNullException ("version");
-                       return version.Envelope == EnvelopeVersion.Soap11 ? 
soap11 : soap12;
+                       return new SimpleFaultConverter (version);
                }
 
                protected FaultConverter ()
                {
                }
 
+               [MonoTODO]
                protected abstract bool OnTryCreateException (
                        Message message, MessageFault fault, out Exception 
error);
 
+               [MonoTODO]
                protected abstract bool OnTryCreateFaultMessage (
                        Exception error, out Message message);
 
@@ -65,31 +63,35 @@
                        return OnTryCreateFaultMessage (error, out message);
                }
 
-               class Soap12FaultConverter : FaultConverter
+               Message CreateSimpleFaultMessage (Exception error, 
MessageVersion version)
                {
-                       public Soap12FaultConverter ()
-                       {
-                       }
+Console.WriteLine (error);
+                       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);
 
-                       protected override bool OnTryCreateException (
-                               Message message, MessageFault fault, out 
Exception error)
-                       {
-                               error = null;
-                               return false;
-                       }
-
-                       protected override bool OnTryCreateFaultMessage (
-                               Exception error, out Message message)
-                       {
-                               message = null;
-                               return false;
-                       }
+                       ExceptionDetail detail = 
+                               
ctx.EndpointDispatcher.ChannelDispatcher.IncludeExceptionDetailInFaults ?
+                               new ExceptionDetail (error) : null;
+                       // FIXME: set correct fault reason.
+                       return Message.CreateMessage (version, fc,
+                               "error occured", detail, 
ctx.IncomingMessageHeaders.Action);
                }
 
-               class Soap11FaultConverter : FaultConverter
+               class SimpleFaultConverter : FaultConverter
                {
-                       public Soap11FaultConverter ()
+                       MessageVersion version;
+                       public SimpleFaultConverter (MessageVersion version)
                        {
+                               this.version = version;
                        }
 
                        protected override bool OnTryCreateException (
@@ -103,7 +105,11 @@
                                Exception error, out Message message)
                        {
                                message = null;
-                               return false;
+                               if (OperationContext.Current == null)
+                                       return false;
+
+                               message = CreateSimpleFaultMessage (error, 
version);
+                               return true;
                        }
                }
        }

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecurityRequestContext.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecurityRequestContext.cs
        2007-03-07 09:30:43 UTC (rev 73878)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Channels/SecurityRequestContext.cs
        2007-03-07 12:03:37 UTC (rev 73879)
@@ -49,6 +49,7 @@
                SecurityReplyChannel channel;
                RequestContext source;
                Message msg;
+               MessageBuffer source_request;
 
                public SecurityRequestContext (SecurityReplyChannel channel, 
RequestContext source)
                {
@@ -58,10 +59,24 @@
                        security = channel.Source.SecuritySupport;
                }
 
+               MessageBuffer SourceBuffer {
+                       get {
+                               if (source_request == null)
+                                       source_request = 
source.RequestMessage.CreateBufferedCopy (0x10000);
+                               return source_request;
+                       }
+               }
+
                public override Message RequestMessage {
                        get {
-                               if (msg == null)
-                                       msg = new 
RecipientSecureMessageDecryptor (source.RequestMessage, 
security).DecryptMessage ();
+                               if (msg == null) {
+                                       try {
+                                               msg = new 
RecipientSecureMessageDecryptor (SourceBuffer.CreateMessage (), 
security).DecryptMessage ();
+                                       } finally {
+                                               if (msg == null)
+                                                       msg = 
SourceBuffer.CreateMessage ();
+                                       }
+                               }
                                return msg;
                        }
                }
@@ -105,8 +120,17 @@
 
                public override void Reply (Message message, TimeSpan timeout)
                {
-                       message = SecureMessage (message);
-                       source.Reply (message, timeout);
+                       try {
+                               message = SecureMessage (message);
+                               source.Reply (message, timeout);
+                       } catch (Exception ex) {
+                               FaultConverter fc = 
FaultConverter.GetDefaultFaultConverter (msg.Version);
+                               Message fault;
+                               if (fc.TryCreateFaultMessage (ex, out fault))
+                                       source.Reply (fault, timeout);
+                               else
+                                       throw;
+                       }
                }
 
                Message SecureMessage (Message input)

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChangeLog  
    2007-03-07 09:30:43 UTC (rev 73878)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChangeLog  
    2007-03-07 12:03:37 UTC (rev 73879)
@@ -1,5 +1,12 @@
 2007-03-07  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * EndpointDispatcher.cs : use ErrorHandlers when error was raised.
+         Handle exceptions to make into SOAP Fault, using FaultConverter.
+       * ChannelDispatcher.cs : simply get ServiceEndpoint at Attach().
+       * ChannelDispatcherBase.cs : removed MonoTODOs.
+
+2007-03-07  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * ChannelDispatcher.cs, DispatchRuntime.cs, EndpointDispatcher.cs :
          moved most of request/input processing to EndpointDispatcher.cs.
          Also, ChannelDispatcher now contains code for behavior

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcher.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcher.cs
   2007-03-07 09:30:43 UTC (rev 73878)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcher.cs
   2007-03-07 12:03:37 UTC (rev 73879)
@@ -40,6 +40,8 @@
        public class ChannelDispatcher : ChannelDispatcherBase
        {
                ServiceHostBase host;
+               ServiceEndpoint service_endpoint;
+
                string binding_name;
                EndpointDispatcher endpoint_dispatcher;
                Collection<IErrorHandler> error_handlers
@@ -180,6 +182,7 @@
                {
                        this.host = host;
                        ServiceEndpoint se = FindEndpoint ();
+                       service_endpoint = se;
                        // FIXME: raise an error in case endpoint was not found.
 
                        endpoint_dispatcher = new EndpointDispatcher (
@@ -264,7 +267,11 @@
                        host.ChannelDispatchers.Remove (this);
                }
 
-               internal ServiceEndpoint FindEndpoint ()
+               internal ServiceEndpoint ServiceEndpoint {
+                       get { return service_endpoint; }
+               }
+
+               ServiceEndpoint FindEndpoint ()
                {
                        foreach (ServiceEndpoint se in 
host.Description.Endpoints)
                                if (se.Binding.Name == BindingName)

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcherBase.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcherBase.cs
       2007-03-07 09:30:43 UTC (rev 73878)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcherBase.cs
       2007-03-07 12:03:37 UTC (rev 73879)
@@ -40,17 +40,14 @@
 
                public abstract ServiceHostBase Host { get; }
 
-               [MonoTODO ("umm, why are they virtual?")]
                protected internal virtual void Attach (ServiceHostBase host)
                {
                }
 
-               [MonoTODO ("umm, why are they virtual?")]
                public virtual void CloseInput ()
                {
                }
 
-               [MonoTODO ("umm, why are they virtual?")]
                protected internal virtual void Detach (ServiceHostBase host)
                {
                }

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/EndpointDispatcher.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/EndpointDispatcher.cs
  2007-03-07 09:30:43 UTC (rev 73878)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Dispatcher/EndpointDispatcher.cs
  2007-03-07 12:03:37 UTC (rev 73879)
@@ -123,65 +123,75 @@
                                DoProcessRequest (reply);
                        } catch (Exception ex) {
 Console.WriteLine (ex);
-                               // FIXME: will we need to do something (like 
error logging) here.
+                               HandleError (ex);
                        }
                }
 
                void DoProcessRequest (IReplyChannel reply)
                {
-                       ServiceEndpoint se = channel_dispatcher.FindEndpoint ();
+                       ServiceEndpoint se = channel_dispatcher.ServiceEndpoint;
                        IServiceChannel cch = new ServiceRuntimeChannel (se, 
reply);
-                       // FIXME: some kind of extra consideration to
-                       // create transport-level RequestContext is
-                       // needed, to handle errors on wrapping
-                       // RequestContext layers (such as 
-                       // SecurityRequestContext). Currently there
-                       // is no way to catch those errors and return
-                       // it as SOAP Fault...
-                       RequestContext rc = reply.ReceiveRequest 
(se.Binding.ReceiveTimeout);
-                       if (rc == null)
-                               // FIXME: probably some kind of reporting is 
required.
-                               return;
-                       if (IsMessageFilteredOut (rc.RequestMessage)) {
-                               rc.Reply (CreateDestinationUnreachable 
(rc.RequestMessage));
-                               // FIXME: probably some kind of reporting is 
required.
-                               return;
-                       }
                        using (OperationContextScope scope = new 
OperationContextScope (cch)) {
                                OperationContext.Current.EndpointDispatcher = 
this;
+                               RequestContext rc = reply.ReceiveRequest 
(se.Binding.ReceiveTimeout);
+                               if (rc == null)
+                                       throw new InvalidOperationException 
("The reply channel didn't return RequestContext");
                                OperationContext.Current.RequestContext = rc;
-
-                               Message req = rc.RequestMessage;
-                               DispatchOperation op = GetOperation (req);
-                               Message res = op.ProcessRequest (req);
-                               if (res == null)
-                                       throw new InvalidOperationException 
(String.Format ("The operation '{0}' returned a null message.", op.Action));
-                               rc.Reply (res, se.Binding.SendTimeout);
+                               // This covers some kind of extra consideration
+                               // to catch errors and replies SOAP fault. It
+                               // still depends on the channel implementation
+                               // to not raise errors instead of replying
+                               // fault at Reply() though ...
+                               try {
+                                       ProcessRequestCore (reply, cch, rc);
+                               } catch (Exception ex) {
+                                       FaultConverter fc = 
FaultConverter.GetDefaultFaultConverter (channel_dispatcher.MessageVersion);
+                                       Message fault;
+                                       if (fc.TryCreateFaultMessage (ex, out 
fault))
+                                               rc.Reply (fault, 
se.Binding.SendTimeout);
+                                       else
+                                               throw;
+                               }
                        }
                }
 
+               void ProcessRequestCore (IReplyChannel reply, IServiceChannel 
cch, RequestContext rc)
+               {
+                       ServiceEndpoint se = channel_dispatcher.ServiceEndpoint;
+                       if (IsMessageFilteredOut (rc.RequestMessage))
+                               throw new EndpointNotFoundException 
(String.Format ("The request message has the target '{0}' which is not 
reachable in this service contract", rc.RequestMessage.Headers.To));
+
+                       Message req = rc.RequestMessage;
+                       DispatchOperation op = GetOperation (req);
+                       Message res = op.ProcessRequest (req);
+                       if (res == null)
+                               throw new InvalidOperationException 
(String.Format ("The operation '{0}' returned a null message.", op.Action));
+                       rc.Reply (res, se.Binding.SendTimeout);
+               }
+
                internal void ProcessInput (IInputChannel input)
                {
                        try {
                                DoProcessInput (input);
                        } catch (Exception ex) {
 Console.WriteLine (ex);
-                       // FIXME: will we need to do something (like error 
logging) here.
+                               HandleError (ex);
                        }
                }
 
                void DoProcessInput (IInputChannel input)
                {
-                       ServiceEndpoint se = channel_dispatcher.FindEndpoint ();
+                       ServiceEndpoint se = channel_dispatcher.ServiceEndpoint;
                        IServiceChannel cch = new ServiceRuntimeChannel (se, 
input);
-                       Message msg = input.Receive (se.Binding.ReceiveTimeout);
-                       if (IsMessageFilteredOut (msg)) {
-Console.WriteLine ("Input message was filtered out.");
-                               // FIXME: will we need to do something (like 
error logging) here.
-                               return;
-                       }
                        using (OperationContextScope scope = new 
OperationContextScope (cch)) {
                                OperationContext.Current.EndpointDispatcher = 
this;
+                               // IInputChannel is simpler since it does
+                               // not have to return SOAP Fault.
+
+                               Message msg = input.Receive 
(se.Binding.ReceiveTimeout);
+                               if (IsMessageFilteredOut (msg))
+                                       throw new EndpointNotFoundException 
(String.Format ("The input message has the target '{0}' which is not reachable 
in this service contract", msg.Headers.To));
+
                                DispatchOperation op = GetOperation (msg);
                                op.ProcessInput (msg);
                        }
@@ -214,14 +224,11 @@
                        return DispatchRuntime.UnhandledDispatchOperation;
                }
                
-               Message CreateDestinationUnreachable (Message req)
+               void HandleError (Exception ex)
                {
-                       FaultCode fc = new FaultCode (
-                               "DestinationUnreachable",
-                               req.Version.Addressing.Namespace);
-                       // FIXME: set correct namespace URI
-                       return Message.CreateMessage (req.Version, fc,
-                               String.Format ("No endpoint found for message 
with To '{0}'", req.Headers.To), String.Empty);
+                       foreach (IErrorHandler handler in 
channel_dispatcher.ErrorHandlers)
+                               if (handler.HandleError (ex))
+                                       break;
                }
 
                #endregion

Modified: trunk/olive/class/System.ServiceModel/System.ServiceModel.dll.sources
===================================================================
--- trunk/olive/class/System.ServiceModel/System.ServiceModel.dll.sources       
2007-03-07 09:30:43 UTC (rev 73878)
+++ trunk/olive/class/System.ServiceModel/System.ServiceModel.dll.sources       
2007-03-07 12:03:37 UTC (rev 73879)
@@ -708,6 +708,7 @@
 System.ServiceModel/EndpointIdentity.cs
 System.ServiceModel/EndpointNotFoundException.cs
 System.ServiceModel/EnvelopeVersion.cs
+System.ServiceModel/ExceptionDetail.cs
 System.ServiceModel/ExtensionCollection.cs
 System.ServiceModel/FaultCode.cs
 System.ServiceModel/FaultContractAttribute.cs

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to