Ejemplo n.º 1
0
		protected override bool ProcessRequest (MessageProcessingContext mrc)
		{
			Exception ex = mrc.ProcessingException;
			DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
			
			//invoke all user handlers
			ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;
			foreach (IErrorHandler handler in channelDispatcher.ErrorHandlers)
				if (handler.HandleError (ex))
					break;

			// FIXME: remove them. FaultConverter also covers errors like EndpointNotFoundException, which this handler never covers. And checking converter twice is extraneous, so this part is just extraneous.
			// FIXME: actually everything is done in OperationInvokerHandler now...
			FaultConverter fc = FaultConverter.GetDefaultFaultConverter (dispatchRuntime.ChannelDispatcher.MessageVersion);
			Message res = null;			
			if (!fc.TryCreateFaultMessage (ex, out res))
				throw ex;
			mrc.ReplyMessage = res;

			if (duplex != null)
				mrc.Reply (duplex, true);
			else
				mrc.Reply (true);
			return false;
		}		
		void FinishRequest (MessageProcessingContext mrc)
		{				
			if (mrc.Operation != null &&  mrc.Operation.ReleaseInstanceAfterCall) {
				mrc.InstanceContext.ReleaseServiceInstance ();
			}
			mrc.InstanceContext.CloseIfIdle ();			
		}
Ejemplo n.º 3
0
        void DoProcessRequest(MessageProcessingContext mrc)
        {
            DispatchOperation operation = mrc.Operation;
            Message           req       = mrc.IncomingMessage;
            object            instance  = mrc.InstanceContext.GetServiceInstance(req);

            object [] parameters, outParams;
            BuildInvokeParams(mrc, out parameters);

            if (operation.Invoker.IsSynchronous)
            {
                object result = operation.Invoker.Invoke(instance, parameters, out outParams);
                HandleInvokeResult(mrc, outParams, result);
            }
            else
            {
                AsyncCallback callback = delegate {};
                // FIXME: the original code passed null callback
                // and null state, which is very wrong :(
                // It is still wrong to pass dummy callback, but
                // wrong code without obvious issues is better
                // than code with an obvious issue.
                var    ar     = operation.Invoker.InvokeBegin(instance, parameters, callback, null);
                object result = operation.Invoker.InvokeEnd(instance, out outParams, ar);
                HandleInvokeResult(mrc, outParams, result);
            }
        }
Ejemplo n.º 4
0
 void ReplyNegoResponse(MessageProcessingContext mrc, Message negoResponse)
 {
     negoResponse.Headers.CopyHeadersFrom(mrc.OperationContext.OutgoingMessageHeaders);
     negoResponse.Properties.CopyProperties(mrc.OperationContext.OutgoingMessageProperties);
     mrc.RequestContext.Reply(negoResponse, mrc.Operation.Parent.ChannelDispatcher.timeouts.SendTimeout);
     return;
 }
		void ReplyNegoResponse (MessageProcessingContext mrc, Message negoResponse)
		{
			negoResponse.Headers.CopyHeadersFrom (mrc.OperationContext.OutgoingMessageHeaders);
			negoResponse.Properties.CopyProperties (mrc.OperationContext.OutgoingMessageProperties);			
			mrc.RequestContext.Reply (negoResponse, mrc.Operation.Parent.ChannelDispatcher.timeouts.SendTimeout);
			return;
		}
Ejemplo n.º 6
0
        protected virtual void ProcessRequest(MessageProcessingContext mrc)
        {
            initialize_handlers_chain.ProcessRequestChain(mrc);

            using (new OperationContextScope(mrc.OperationContext))
            {
                try
                {
                    process_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);
                }
            }
        }
		protected override bool ProcessRequest (MessageProcessingContext mrc)
		{
			DispatchRuntime dispatch_runtime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;

			// FIXME: I doubt this should be done at this "handler" 
			// layer, especially considering about non-ServiceHost
			// use of SecurityBindingElement + listener.
			//
			// For example there is no way to handle it in duplex
			// dispatch callbacks.
			if (dispatch_runtime.ChannelDispatcher == null)
				return false;

			Message negoResponce = null;
			// process WS-Trust based negotiation
			MessageSecurityBindingSupport support =
				dispatch_runtime.ChannelDispatcher.Listener.GetProperty<MessageSecurityBindingSupport> ();
			if (support != null && mrc.IncomingMessage.Headers.FindHeader ("Security", Constants.WssNamespace) < 0) {
				CommunicationSecurityTokenAuthenticator nego =
					support.TokenAuthenticator as CommunicationSecurityTokenAuthenticator;
				if (nego != null)
					negoResponce = nego.Communication.ProcessNegotiation (mrc.IncomingMessage);
			}

			if (negoResponce == null)
				return false;
			
			ReplyNegoResponse (mrc, negoResponce);
			return true;

		}
Ejemplo n.º 8
0
        void HandleInvokeResult(MessageProcessingContext mrc, object [] outputs, object result)
        {
            DispatchOperation operation = mrc.Operation;

            mrc.EventsHandler.AfterInvoke(operation);

            if (operation.IsOneWay)
            {
                return;
            }

            Message res = null;

            if (operation.SerializeReply)
            {
                res = operation.Formatter.SerializeReply(
                    mrc.OperationContext.IncomingMessageVersion, outputs, result);
            }
            else
            {
                res = (Message)result;
            }
            res.Headers.CopyHeadersFrom(mrc.OperationContext.OutgoingMessageHeaders);
            res.Properties.CopyProperties(mrc.OperationContext.OutgoingMessageProperties);
            if (res.Headers.RelatesTo == null)
            {
                res.Headers.RelatesTo = mrc.OperationContext.IncomingMessageHeaders.MessageId;
            }
            mrc.ReplyMessage = res;
        }
Ejemplo n.º 9
0
		Message BuildExceptionMessage (MessageProcessingContext mrc, Exception ex, bool includeDetailsInFault)
		{
			var dr = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
			var cd = dr.ChannelDispatcher;
			Message msg = null;
			foreach (var eh in cd.ErrorHandlers)
				eh.ProvideFault (ex, cd.MessageVersion, ref msg);
			if (msg != null)
				return msg;

			var req = mrc.IncomingMessage;

			// FIXME: set correct name
			FaultCode fc = new FaultCode (
				"InternalServiceFault",
				req.Version.Addressing.Namespace);


			if (includeDetailsInFault) {
				return Message.CreateMessage (req.Version, fc, ex.Message, new ExceptionDetail (ex), req.Headers.Action);
			}

			string faultString =
				@"The server was unable to process the request due to an internal error.  The server may be able to return exception details (it depends on the server settings).";
			return Message.CreateMessage (req.Version, fc, faultString, req.Headers.Action);
		}
Ejemplo n.º 10
0
 public void ProcessRequestChain(MessageProcessingContext mrc)
 {
     if (chain != null)
     {
         chain.ProcessRequestChain(mrc);
     }
 }
Ejemplo n.º 11
0
 public virtual void ProcessRequestChain(MessageProcessingContext mrc)
 {
     if (!ProcessRequest(mrc) && next != null)
     {
         next.ProcessRequestChain(mrc);
     }
 }
Ejemplo n.º 12
0
		void Reply (MessageProcessingContext mrc, bool useTimeout)
		{
			if (duplex != null)
				mrc.Reply (duplex, useTimeout);
			else
				mrc.Reply (useTimeout);
		}
Ejemplo n.º 13
0
        InstanceContext CreateInstanceContext(MessageProcessingContext mrc)
        {
            InstanceContext          iCtx            = null;
            DispatchRuntime          dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
            IInstanceContextProvider p = dispatchRuntime.InstanceContextProvider;

            if (p != null)
            {
                iCtx = p.GetExistingInstanceContext(mrc.IncomingMessage, mrc.OperationContext.Channel);
            }
            if (iCtx == null)
            {
                ServiceHostBase host = dispatchRuntime.ChannelDispatcher.Host;
                iCtx = new InstanceContext(dispatchRuntime.ChannelDispatcher.Host, null, false);
                // FIXME: could be easier way to identify session channel
                if ((mrc.Channel is ISessionChannel <IInputSession> || mrc.Channel is ISessionChannel <IDuplexSession>) && host.Description.Behaviors.Find <ServiceBehaviorAttribute> ().InstanceContextMode == InstanceContextMode.PerSession)
                {
                    mrc.Channel.Closed += delegate { iCtx.Close(); }
                }
                ;
            }

            iCtx.InstanceManager = new InstanceManager(dispatchRuntime);
            return(iCtx);
        }
    }
Ejemplo n.º 14
0
        protected override bool ProcessRequest(MessageProcessingContext mrc)
        {
            Exception       ex = mrc.ProcessingException;
            DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;

            //invoke all user handlers
            ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;

            foreach (IErrorHandler handler in channelDispatcher.ErrorHandlers)
            {
                if (handler.HandleError(ex))
                {
                    break;
                }
            }

            FaultConverter fc  = FaultConverter.GetDefaultFaultConverter(dispatchRuntime.ChannelDispatcher.MessageVersion);
            Message        res = null;

            if (!fc.TryCreateFaultMessage(ex, out res))
            {
                throw ex;
            }
            mrc.ReplyMessage = res;
            if (duplex != null)
            {
                mrc.Reply(duplex, true);
            }
            else
            {
                mrc.Reply(true);
            }
            return(false);
        }
Ejemplo n.º 15
0
        protected override bool ProcessRequest(MessageProcessingContext mrc)
        {
            RequestContext    rc = mrc.RequestContext;
            DispatchRuntime   dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
            DispatchOperation operation       = GetOperation(mrc.IncomingMessage, dispatchRuntime);

            mrc.Operation = operation;
            try
            {
                DoProcessRequest(mrc);
                if (!mrc.Operation.IsOneWay)
                {
                    Reply(mrc, true);
                }
            }
            catch (TargetInvocationException ex)
            {
                mrc.ReplyMessage = BuildExceptionMessage(mrc, ex.InnerException,
                                                         dispatchRuntime.ChannelDispatcher.IncludeExceptionDetailInFaults);
                if (!mrc.Operation.IsOneWay)
                {
                    Reply(mrc, true);
                }
                ProcessCustomErrorHandlers(mrc, ex);
            }
            return(false);
        }
		protected override bool ProcessRequest (MessageProcessingContext mrc)
		{
			InstanceContext ictx = CreateInstanceContext (mrc);
			mrc.InstanceContext = ictx;
			mrc.OperationContext.InstanceContext = ictx;
			return false;
		}
Ejemplo n.º 17
0
 public UserEventsHandler(MessageProcessingContext mrc)
 {
     request_context       = mrc;
     dispatch_runtime      = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
     msg_inspectors_states = new object [dispatch_runtime.MessageInspectors.Count];
     channel = request_context.OperationContext.Channel as IClientChannel;
 }
Ejemplo n.º 18
0
		void FinishRequest (MessageProcessingContext mrc)
		{
			if (mrc.Operation != null &&  mrc.Operation.IsTerminating && mrc.OperationContext.Channel.InputSession != null)
				mrc.OperationContext.Channel.Close (); // FIXME: timeout?
			if (mrc.Operation != null &&  mrc.Operation.ReleaseInstanceAfterCall)
				mrc.InstanceContext.ReleaseServiceInstance ();
			mrc.InstanceContext.CloseIfIdle ();			
		}
Ejemplo n.º 19
0
 void FinishRequest(MessageProcessingContext mrc)
 {
     if (mrc.Operation != null && mrc.Operation.ReleaseInstanceAfterCall)
     {
         mrc.InstanceContext.ReleaseServiceInstance();
     }
     mrc.InstanceContext.CloseIfIdle();
 }
Ejemplo n.º 20
0
        protected override bool ProcessRequest(MessageProcessingContext mrc)
        {
            InstanceContext ictx = CreateInstanceContext(mrc);

            mrc.InstanceContext = ictx;
            mrc.OperationContext.InstanceContext = ictx;
            return(false);
        }
		protected override bool ProcessRequest (MessageProcessingContext mrc)
		{
			Message incomingMessage = mrc.IncomingMessage;
			EnsureInstanceContextOpen (mrc.InstanceContext);
			AfterReceiveRequest (ref incomingMessage, mrc);
			mrc.IncomingMessage = incomingMessage;
			return false;
		}
Ejemplo n.º 22
0
		void ProcessCustomErrorHandlers (MessageProcessingContext mrc, Exception ex)
		{
			var dr = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
			bool shutdown = false;
			foreach (var eh in dr.ChannelDispatcher.ErrorHandlers)
				shutdown |= eh.HandleError (ex);
			if (shutdown)
				ProcessSessionErrorShutdown (mrc);
		}
Ejemplo n.º 23
0
        protected override bool ProcessRequest(MessageProcessingContext mrc)
        {
            Message incomingMessage = mrc.IncomingMessage;

            EnsureInstanceContextOpen(mrc.InstanceContext);
            AfterReceiveRequest(ref incomingMessage, mrc);
            mrc.IncomingMessage = incomingMessage;
            return(false);
        }
Ejemplo n.º 24
0
		void ProcessSessionErrorShutdown (MessageProcessingContext mrc)
		{
			var dr = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
			var session = mrc.OperationContext.Channel.InputSession;
			var dcc = mrc.OperationContext.Channel as IDuplexContextChannel;
			if (session == null || dcc == null)
				return;
			foreach (var h in dr.InputSessionShutdownHandlers)
				h.ChannelFaulted (dcc);
		}
Ejemplo n.º 25
0
 void FinishRequest(MessageProcessingContext mrc)
 {
     if (mrc.Operation != null && mrc.Operation.IsTerminating && mrc.OperationContext.Channel.InputSession != null)
     {
         mrc.OperationContext.Channel.Close();                  // FIXME: timeout?
     }
     if (mrc.Operation != null && mrc.Operation.ReleaseInstanceAfterCall)
     {
         mrc.InstanceContext.ReleaseServiceInstance();
     }
     mrc.InstanceContext.CloseIfIdle();
 }
Ejemplo n.º 26
0
		void BuildInvokeParams (MessageProcessingContext mrc, out object [] parameters)
		{
			DispatchOperation operation = mrc.Operation;
			EnsureValid (operation);

			if (operation.DeserializeRequest) {
				parameters = operation.Invoker.AllocateInputs ();
				operation.Formatter.DeserializeRequest (mrc.IncomingMessage, parameters);
			} else
				parameters = new object [] { mrc.IncomingMessage };

			mrc.EventsHandler.BeforeInvoke (operation);
		}
Ejemplo n.º 27
0
		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);
				}
			}
		}
Ejemplo n.º 28
0
        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);
                }
            }
        }
Ejemplo n.º 29
0
		void DoProcessRequest (MessageProcessingContext mrc)
		{
			DispatchOperation operation = mrc.Operation;
			Message req = mrc.IncomingMessage;
			object instance = mrc.InstanceContext.GetServiceInstance(req);
			object [] parameters, outParams;
			BuildInvokeParams (mrc, out parameters);

			if (operation.Invoker.IsSynchronous) {
				object result = operation.Invoker.Invoke (instance, parameters, out outParams);
				HandleInvokeResult (mrc, outParams, result);
			} else {
				var ar = operation.Invoker.InvokeBegin (instance, parameters, null, null);
				object result = operation.Invoker.InvokeEnd (instance, out outParams, ar);
				HandleInvokeResult (mrc, outParams, result);
			}
		}
		InstanceContext CreateInstanceContext (MessageProcessingContext mrc)
		{
			InstanceContext iCtx = null;
			DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
			IInstanceContextProvider p = dispatchRuntime.InstanceContextProvider;

			if (p != null) {
				iCtx = p.GetExistingInstanceContext (mrc.IncomingMessage, mrc.OperationContext.Channel);
			}
			if (iCtx == null) {
				ServiceHostBase host = dispatchRuntime.ChannelDispatcher.Host;
				iCtx = new InstanceContext (dispatchRuntime.ChannelDispatcher.Host, null, false);
			}

			iCtx.Behavior = new InstanceBehavior (dispatchRuntime);
			return iCtx;
		}		
Ejemplo n.º 31
0
		void HandleInvokeResult (MessageProcessingContext mrc, object [] outputs, object result)
		{
			DispatchOperation operation = mrc.Operation;
			mrc.EventsHandler.AfterInvoke (operation);

			if (operation.IsOneWay)
				return;

			Message res = null;
			if (operation.SerializeReply)
				res = operation.Formatter.SerializeReply (
					mrc.OperationContext.EndpointDispatcher.ChannelDispatcher.MessageVersion, outputs, result);
			else
				res = (Message) result;
			res.Headers.CopyHeadersFrom (mrc.OperationContext.OutgoingMessageHeaders);
			res.Properties.CopyProperties (mrc.OperationContext.OutgoingMessageProperties);
			mrc.ReplyMessage = res;
		}
Ejemplo n.º 32
0
        InstanceContext CreateInstanceContext(MessageProcessingContext mrc)
        {
            InstanceContext          iCtx            = null;
            DispatchRuntime          dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
            IInstanceContextProvider p = dispatchRuntime.InstanceContextProvider;

            if (p != null)
            {
                iCtx = p.GetExistingInstanceContext(mrc.IncomingMessage, mrc.OperationContext.Channel);
            }
            if (iCtx == null)
            {
                ServiceHostBase host = dispatchRuntime.ChannelDispatcher.Host;
                iCtx = new InstanceContext(dispatchRuntime.ChannelDispatcher.Host, null, false);
            }

            iCtx.InstanceManager = new InstanceManager(dispatchRuntime);
            return(iCtx);
        }
		protected override bool ProcessRequest (MessageProcessingContext mrc)
		{			
			RequestContext rc = mrc.RequestContext;
			DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
			DispatchOperation operation = GetOperation (mrc.IncomingMessage, dispatchRuntime);
			mrc.Operation = operation;
			try {				
				DoProcessRequest (mrc);
				if (!mrc.Operation.IsOneWay)
					Reply (mrc, true);
			} catch (TargetInvocationException ex) {
				mrc.ReplyMessage = BuildExceptionMessage (mrc, ex.InnerException, 
					dispatchRuntime.ChannelDispatcher.IncludeExceptionDetailInFaults);
				if (!mrc.Operation.IsOneWay)
					Reply (mrc, true);
				ProcessCustomErrorHandlers (mrc, ex);
			}
			return false;
		}
Ejemplo n.º 34
0
		InstanceContext CreateInstanceContext (MessageProcessingContext mrc)
		{
			InstanceContext iCtx = null;
			DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
			IInstanceContextProvider p = dispatchRuntime.InstanceContextProvider;

			if (p != null) {
				iCtx = p.GetExistingInstanceContext (mrc.IncomingMessage, mrc.OperationContext.Channel);
			}
			if (iCtx == null) {
				ServiceHostBase host = dispatchRuntime.ChannelDispatcher.Host;
				iCtx = new InstanceContext (dispatchRuntime.ChannelDispatcher.Host, null, false);
				// FIXME: could be easier way to identify session channel
				if ((mrc.Channel is ISessionChannel<IInputSession> || mrc.Channel is ISessionChannel<IDuplexSession>) && host.Description.Behaviors.Find<ServiceBehaviorAttribute> ().InstanceContextMode == InstanceContextMode.PerSession)
					mrc.Channel.Closed += delegate { iCtx.Close (); };
			}

			iCtx.InstanceManager = new InstanceManager (dispatchRuntime);
			return iCtx;
		}		
		protected override bool ProcessRequest (MessageProcessingContext mrc)
		{
			Exception ex = mrc.ProcessingException;
			DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
			
			//invoke all user handlers
			ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;
			foreach (IErrorHandler handler in channelDispatcher.ErrorHandlers)
				if (handler.HandleError (ex))
					break;

			FaultConverter fc = FaultConverter.GetDefaultFaultConverter (dispatchRuntime.ChannelDispatcher.MessageVersion);
			Message res = null;			
			if (!fc.TryCreateFaultMessage (ex, out res))
				throw ex;
			mrc.ReplyMessage = res;
			if (duplex != null)
				mrc.Reply (duplex, true);
			else
				mrc.Reply (true);
			return false;
		}		
Ejemplo n.º 36
0
        protected override bool ProcessRequest(MessageProcessingContext mrc)
        {
            DispatchRuntime dispatch_runtime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;

            // FIXME: I doubt this should be done at this "handler"
            // layer, especially considering about non-ServiceHost
            // use of SecurityBindingElement + listener.
            //
            // For example there is no way to handle it in duplex
            // dispatch callbacks.
            if (dispatch_runtime.ChannelDispatcher == null)
            {
                return(false);
            }

            Message negoResponce = null;
            // process WS-Trust based negotiation
            MessageSecurityBindingSupport support =
                dispatch_runtime.ChannelDispatcher.Listener.GetProperty <MessageSecurityBindingSupport> ();

            if (support != null && mrc.IncomingMessage.Headers.FindHeader("Security", Constants.WssNamespace) < 0)
            {
                CommunicationSecurityTokenAuthenticator nego =
                    support.TokenAuthenticator as CommunicationSecurityTokenAuthenticator;
                if (nego != null)
                {
                    negoResponce = nego.Communication.ProcessNegotiation(mrc.IncomingMessage);
                }
            }

            if (negoResponce == null)
            {
                return(false);
            }

            ReplyNegoResponse(mrc, negoResponce);
            return(true);
        }
Ejemplo n.º 37
0
		void DoProcessRequest (MessageProcessingContext mrc)
		{
			DispatchOperation operation = mrc.Operation;
			Message req = mrc.IncomingMessage;
			object instance = mrc.InstanceContext.GetServiceInstance(req);
			object [] parameters, outParams;
			BuildInvokeParams (mrc, out parameters);

			if (operation.Invoker.IsSynchronous) {
				object result = operation.Invoker.Invoke (instance, parameters, out outParams);
				HandleInvokeResult (mrc, outParams, result);
			} else {
				AsyncCallback callback = delegate {};
				// FIXME: the original code passed null callback
				// and null state, which is very wrong :(
				// It is still wrong to pass dummy callback, but
				// wrong code without obvious issues is better
				// than code with an obvious issue.
				var ar = operation.Invoker.InvokeBegin (instance, parameters, callback, null);
				object result = operation.Invoker.InvokeEnd (instance, out outParams, ar);
				HandleInvokeResult (mrc, outParams, result);
			}
		}
Ejemplo n.º 38
0
		protected virtual void ProcessRequest (MessageProcessingContext mrc)
		{
			initialize_handlers_chain.ProcessRequestChain (mrc);

			using (new OperationContextScope (mrc.OperationContext)) {
				try {
					process_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);
				}
			}
		}
Ejemplo n.º 39
0
        void InvokeAsynchronous(MessageProcessingContext mrc, object instance, object [] parameters)
        {
            DispatchOperation operation       = mrc.Operation;
            DispatchRuntime   dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;

            operation.Invoker.InvokeBegin(instance, parameters,
                                          delegate(IAsyncResult res) {
                try {
                    object result;
                    result = operation.Invoker.InvokeEnd(instance, out parameters, res);
                    HandleInvokeResult(mrc, parameters, result);
                    Reply(mrc, true);
                } catch (Exception ex) {
                    mrc.ReplyMessage = BuildExceptionMessage(mrc, ex, dispatchRuntime.ChannelDispatcher.IncludeExceptionDetailInFaults);
                    if (!mrc.Operation.IsOneWay)
                    {
                        Reply(mrc, false);
                    }
                    ProcessCustomErrorHandlers(mrc, ex);
                }
            },
                                          null);
        }
Ejemplo n.º 40
0
        protected override bool ProcessRequest(MessageProcessingContext mrc)
        {
            Exception       ex = mrc.ProcessingException;
            DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;

            //invoke all user handlers
            ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;

            foreach (IErrorHandler handler in channelDispatcher.ErrorHandlers)
            {
                if (handler.HandleError(ex))
                {
                    break;
                }
            }

            // FIXME: remove them. FaultConverter also covers errors like EndpointNotFoundException, which this handler never covers. And checking converter twice is extraneous, so this part is just extraneous.
            // FIXME: actually everything is done in OperationInvokerHandler now...
            FaultConverter fc  = FaultConverter.GetDefaultFaultConverter(dispatchRuntime.ChannelDispatcher.MessageVersion);
            Message        res = null;

            if (!fc.TryCreateFaultMessage(ex, out res))
            {
                throw ex;
            }
            mrc.ReplyMessage = res;

            if (duplex != null)
            {
                mrc.Reply(duplex, true);
            }
            else
            {
                mrc.Reply(true);
            }
            return(false);
        }
Ejemplo n.º 41
0
		Message BuildExceptionMessage (MessageProcessingContext mrc, Exception ex, bool includeDetailsInFault)
		{
			var dr = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
			var cd = dr.ChannelDispatcher;
			Message msg = null;
			if (cd != null) // non-callback channel
				foreach (var eh in cd.ErrorHandlers)
					eh.ProvideFault (ex, cd.MessageVersion, ref msg);
			if (msg != null)
				return msg;

			var req = mrc.IncomingMessage;

			Type gft;
			var fe = ex as FaultException;
			if (fe != null && IsGenericFaultException (fe.GetType (), out gft)) {
				foreach (var fci in mrc.Operation.FaultContractInfos) {
					if (fci.Detail == gft)
						return Message.CreateMessage (req.Version, fe.CreateMessageFault (), fci.Action);
				}
			}

			// FIXME: set correct name
			FaultCode fc = new FaultCode (
				"InternalServiceFault",
				req.Version.Addressing.Namespace);


			if (includeDetailsInFault) {
				return Message.CreateMessage (req.Version, fc, ex.Message, new ExceptionDetail (ex), req.Headers.Action);
			}

			string faultString =
				@"The server was unable to process the request due to an internal error.  The server may be able to return exception details (it depends on the server settings).";
			return Message.CreateMessage (req.Version, fc, faultString, req.Headers.Action);
		}
Ejemplo n.º 42
0
		public void ProcessRequestChain (MessageProcessingContext mrc)
		{
			if (chain != null)
				chain.ProcessRequestChain (mrc);
		}
Ejemplo n.º 43
0
        void BuildInvokeParams(MessageProcessingContext mrc, out object [] parameters)
        {
            DispatchOperation operation = mrc.Operation;

            EnsureValid(operation);

            if (operation.DeserializeRequest)
            {
                parameters = operation.Invoker.AllocateInputs();
                operation.Formatter.DeserializeRequest(mrc.IncomingMessage, parameters);
            }
            else
            {
                parameters = new object [] { mrc.IncomingMessage }
            };

            mrc.EventsHandler.BeforeInvoke(operation);
        }

        void ProcessCustomErrorHandlers(MessageProcessingContext mrc, Exception ex)
        {
            var  dr       = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
            bool shutdown = false;

            if (dr.ChannelDispatcher != null) // non-callback channel
            {
                foreach (var eh in dr.ChannelDispatcher.ErrorHandlers)
                {
                    shutdown |= eh.HandleError(ex);
                }
            }
            if (shutdown)
            {
                ProcessSessionErrorShutdown(mrc);
            }
        }

        void ProcessSessionErrorShutdown(MessageProcessingContext mrc)
        {
            var dr      = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
            var session = mrc.OperationContext.Channel.InputSession;
            var dcc     = mrc.OperationContext.Channel as IDuplexContextChannel;

            if (session == null || dcc == null)
            {
                return;
            }
            foreach (var h in dr.InputSessionShutdownHandlers)
            {
                h.ChannelFaulted(dcc);
            }
        }

        Message BuildExceptionMessage(MessageProcessingContext mrc, Exception ex, bool includeDetailsInFault)
        {
            var     dr  = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
            var     cd  = dr.ChannelDispatcher;
            Message msg = null;

            if (cd != null) // non-callback channel
            {
                foreach (var eh in cd.ErrorHandlers)
                {
                    eh.ProvideFault(ex, cd.MessageVersion, ref msg);
                }
            }
            if (msg != null)
            {
                return(msg);
            }

            var req = mrc.IncomingMessage;

            var fe = ex as FaultException;

            if (fe != null && fe.GetType().IsGenericType)
            {
                var t = fe.GetType().GetGenericArguments() [0];
                foreach (var fci in mrc.Operation.FaultContractInfos)
                {
                    if (fci.Detail == t)
                    {
                        return(Message.CreateMessage(req.Version, fe.CreateMessageFault(), fci.Action));
                    }
                }
            }

            // FIXME: set correct name
            FaultCode fc = new FaultCode(
                "InternalServiceFault",
                req.Version.Addressing.Namespace);


            if (includeDetailsInFault)
            {
                return(Message.CreateMessage(req.Version, fc, ex.Message, new ExceptionDetail(ex), req.Headers.Action));
            }

            string faultString =
                @"The server was unable to process the request due to an internal error.  The server may be able to return exception details (it depends on the server settings).";

            return(Message.CreateMessage(req.Version, fc, faultString, req.Headers.Action));
        }

        void EnsureValid(DispatchOperation operation)
        {
            if (operation.Invoker == null)
            {
                throw new InvalidOperationException(String.Format("DispatchOperation '{0}' for contract '{1}' requires Invoker.", operation.Name, operation.Parent.EndpointDispatcher.ContractName));
            }
            if ((operation.DeserializeRequest || operation.SerializeReply) && operation.Formatter == null)
            {
                throw new InvalidOperationException("The DispatchOperation '" + operation.Name + "' requires Formatter, since DeserializeRequest and SerializeReply are not both false.");
            }
        }
    }
Ejemplo n.º 44
0
		protected override bool ProcessRequest (MessageProcessingContext mrc)
		{
			EnsureInstanceContextOpen (mrc.InstanceContext);
			AfterReceiveRequest (mrc);
			return false;
		}
Ejemplo n.º 45
0
		public UserEventsHandler (MessageProcessingContext mrc)
		{
			request_context = mrc;
			dispatch_runtime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
			msg_inspectors_states = new object [dispatch_runtime.MessageInspectors.Count];
			channel = request_context.OperationContext.Channel as IClientChannel;
		}
Ejemplo n.º 46
0
 void AfterReceiveRequest(MessageProcessingContext mrc)
 {
     mrc.EventsHandler.AfterReceiveRequest();
 }
Ejemplo n.º 47
0
		protected abstract bool ProcessRequest (MessageProcessingContext mrc);
Ejemplo n.º 48
0
 protected override bool ProcessRequest(MessageProcessingContext mrc)
 {
     return(false);
 }
Ejemplo n.º 49
0
 public override void ProcessRequestChain(MessageProcessingContext mrc)
 {
     using (new OperationContextScope(mrc.OperationContext)) {
         base.ProcessRequestChain(mrc);
     }
 }
Ejemplo n.º 50
0
		public override void ProcessRequestChain (MessageProcessingContext mrc)
		{
			using (new OperationContextScope (mrc.OperationContext)) {
				base.ProcessRequestChain (mrc);
			}
		}
Ejemplo n.º 51
0
		protected override bool ProcessRequest (MessageProcessingContext mrc)
		{
			return false;
		}		
		void AfterReceiveRequest (ref Message message, MessageProcessingContext mrc)
		{
			mrc.EventsHandler.AfterReceiveRequest ();
		}
Ejemplo n.º 53
0
		public virtual void ProcessRequestChain (MessageProcessingContext mrc)
		{
			if (!ProcessRequest (mrc) && next != null ) {				
				next.ProcessRequestChain (mrc);
			}
		}