Example #1
0
        /// <summary>
        /// Invokes the method.
        /// </summary>
        /// <typeparam name="S">Type of the request.</typeparam>
        /// <typeparam name="TResponse">Type of the response.</typeparam>
        /// <param name="request">The request.</param>
        /// <param name="workDelegate">The work delegate.</param>
        /// <returns>Message response.</returns>
        protected TResponse InvokeMethod <TResponse>(Func <TChannel, TResponse> workDelegate)
        {
            WcfExceptionDetail exception = null;

            this.LastExceptionDetail = null;
            TResponse response = default(TResponse);

            try
            {
                this.EnsureChannelOpened();
                response = workDelegate(this.InnerChannel);
            }
            catch (FaultException <WcfExceptionDetail> ex)
            {
                exception = ex.Detail;
            }
            catch (FaultException ex)
            {
                exception = new WcfExceptionDetail(ex);
            }
            catch (CommunicationException ex)
            {
                exception = new WcfExceptionDetail(ex);
                this.Close();
            }
            catch (ObjectDisposedException ex)
            {
                exception = new WcfExceptionDetail(ex);
                this.Close();
            }
            catch (TimeoutException ex)
            {
                exception = new WcfExceptionDetail(ex);
                this.Close();
            }
            catch (Exception ex)
            {
                exception = new WcfExceptionDetail(ex);
            }
            finally
            {
                if (response == null)
                {
                    response = Activator.CreateInstance <TResponse>();
                }
                if (response != null &&
                    response is WcfMessageContextBase)
                {
                    WcfMessageContextBase context = response as WcfMessageContextBase;
                    context.Exception = exception;
                }
            }

            this.LastExceptionDetail = exception;
            return(response);
        }
Example #2
0
        /// <summary>
        /// Invokes the method.
        /// </summary>
        /// <typeparam name="S">Type of the request.</typeparam>
        /// <typeparam name="TResponse">Type of the response.</typeparam>
        /// <param name="request">The request.</param>
        /// <param name="workDelegate">The work delegate.</param>
        /// <returns>Message response.</returns>
        protected void InvokeMethod(Action <TChannel> workDelegate)
        {
            WcfExceptionDetail exception = null;

            this.LastExceptionDetail = null;

            try
            {
                this.EnsureChannelOpened();
                workDelegate(this.InnerChannel);
            }
            catch (FaultException <WcfExceptionDetail> ex)
            {
                exception = ex.Detail;
            }
            catch (FaultException ex)
            {
                exception = new WcfExceptionDetail(ex);
            }
            catch (CommunicationException ex)
            {
                exception = new WcfExceptionDetail(ex);
                this.Close();
            }
            catch (ObjectDisposedException ex)
            {
                exception = new WcfExceptionDetail(ex);
                this.Close();
            }
            catch (TimeoutException ex)
            {
                exception = new WcfExceptionDetail(ex);
                this.Close();
            }
            catch (Exception ex)
            {
                exception = new WcfExceptionDetail(ex);
            }

            this.LastExceptionDetail = exception;
        }
Example #3
0
        void IErrorHandler.ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
        {
            // always raise exceptions as FaultException<ExceptionDetail>, it is compulsary
            FaultException <WcfExceptionDetail> exFault = null;

            // already a fault exception of exception detail?
            if (error is FaultException <WcfExceptionDetail> )
            {
                exFault = error as FaultException <WcfExceptionDetail>;
            }
            else
            {
                // not yet, so raise as a fault exception
                WcfExceptionDetail exDetail = new WcfExceptionDetail(error);
                exFault = new FaultException <WcfExceptionDetail>(exDetail, new FaultReason(error.Message));
            }

            // converts the original message into fault message
            MessageFault msgFault = exFault.CreateMessageFault();

            fault = Message.CreateMessage(version, msgFault, WcfExceptionDetail.ACTION);
        }