| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using System;
- using System.Collections.Generic;
- using System.ServiceModel;
- using System.ServiceModel.Channels;
- using System.ServiceModel.Security;
- using System.ServiceModel.Security.Tokens;
- using System.Text;
- using System.IO;
- using System.Xml;
- using System.Net.Sockets;
- namespace System.ServiceModel.Dispatcher
- {
- internal class BaseRequestProcessor
- {
- HandlersChain initialize_handlers_chain = new HandlersChain();
- HandlersChain process_handlers_chain = new HandlersChain ();
- HandlersChain error_handlers_chain = new HandlersChain ();
- HandlersChain finalize_handlers_chain = new HandlersChain ();
- protected BaseRequestProcessor () { }
- protected virtual void ProcessRequest (MessageProcessingContext mrc)
- {
- initialize_handlers_chain.ProcessRequestChain (mrc);
- using (new OperationContextScope (mrc.OperationContext)) {
- try {
- process_handlers_chain.ProcessRequestChain (mrc);
- } catch (IOException e) {
- // FIXME?: On dropped connection do not
- // dump a stacktrace, but should be safe
- // to dump a console message as in
- // default exception handler and
- // call error_handlers_chain
- Console.WriteLine ("I/O Error (Dropped Connection?): " + e.Message);
- mrc.ProcessingException = e;
- error_handlers_chain.ProcessRequestChain (mrc);
- } catch (SocketException e) {
- // FIXME?: On dropped connection do not
- // dump a stacktrace, but should be safe
- // to dump a console message as in
- // default exception handler and
- // call error_handlers_chain
- Console.WriteLine ("SocketExcpetion (Dropped Connection?): " + e.Message);
- mrc.ProcessingException = e;
- error_handlers_chain.ProcessRequestChain (mrc);
- } catch (XmlException e) {
- // FIXME?: On dropped connection do not
- // dump a stacktrace, but should be safe
- // to dump a console message as in
- // default exception handler and
- // call error_handlers_chain
- Console.WriteLine ("XmlException (Dropped Connection?): " + e.Message);
- mrc.ProcessingException = e;
- error_handlers_chain.ProcessRequestChain (mrc);
- } catch (Exception e) {
- // FIXME: this is not really expected use of ChannelDispatcher.ErrorHandlers.
- // They are now correctly used in process_handler_chain (namely OperationInvokerHandler).
- // For this kind of "outsider" exceptions are actually left thrown
- // (and could even cause server loop crash in .NET).
- Console.WriteLine ("Exception " + e.Message + " " + e.StackTrace);
- mrc.ProcessingException = e;
- error_handlers_chain.ProcessRequestChain (mrc);
- }
- finally {
- finalize_handlers_chain.ProcessRequestChain (mrc);
- }
- }
- }
- public HandlersChain InitializeChain
- {
- get { return initialize_handlers_chain; }
- }
- public HandlersChain ProcessingChain
- {
- get { return process_handlers_chain; }
- }
- public HandlersChain ErrorChain
- {
- get { return error_handlers_chain; }
- }
- public HandlersChain FinalizationChain
- {
- get { return finalize_handlers_chain; }
- }
- }
- internal class HandlersChain
- {
- BaseRequestProcessorHandler chain;
- public void ProcessRequestChain (MessageProcessingContext mrc)
- {
- if (chain != null)
- chain.ProcessRequestChain (mrc);
- }
- public HandlersChain AddHandler (BaseRequestProcessorHandler handler)
- {
- if (chain == null) {
- chain = handler;
- }
- else {
- BaseRequestProcessorHandler current = chain;
- while (current.Next != null)
- current = current.Next;
- current.Next = handler;
- }
- return this;
- }
- }
- }
|