public SessionOperationAsyncResult(SecuritySessionSecurityTokenProvider requestor, SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.requestor     = requestor;
                this.operation     = operation;
                this.target        = target;
                this.via           = via;
                this.currentToken  = currentToken;
                this.timeoutHelper = new TimeoutHelper(timeout);
                SecurityTraceRecordHelper.TraceBeginSecuritySessionOperation(operation, target, currentToken);
                bool completeSelf = false;

                try
                {
                    completeSelf = this.StartOperation();
                }
#pragma warning suppress 56500 // covered by FxCOP
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    this.OnOperationFailure(e);
                    throw;
                }
                if (completeSelf)
                {
                    this.OnOperationComplete();
                    Complete(true);
                }
            }
Exemple #2
0
            public SessionOperationAsyncResult(SecuritySessionSecurityTokenProvider requestor, SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
            {
                this.requestor     = requestor;
                this.operation     = operation;
                this.target        = target;
                this.via           = via;
                this.currentToken  = currentToken;
                this.timeoutHelper = new TimeoutHelper(timeout);
                SecurityTraceRecordHelper.TraceBeginSecuritySessionOperation(operation, target, currentToken);
                bool flag = false;

                try
                {
                    flag = this.StartOperation();
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    this.OnOperationFailure(exception);
                    throw;
                }
                if (flag)
                {
                    this.OnOperationComplete();
                    base.Complete(true);
                }
            }
Exemple #3
0
        private GenericXmlSecurityToken DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
        {
            GenericXmlSecurityToken token2;

            if (target == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("target");
            }
            if ((operation == SecuritySessionOperation.Renew) && (currentToken == null))
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("currentToken");
            }
            IRequestChannel channel = null;

            try
            {
                object obj2;
                GenericXmlSecurityToken token;
                SecurityTraceRecordHelper.TraceBeginSecuritySessionOperation(operation, target, currentToken);
                channel = this.CreateChannel(operation, target, via);
                TimeoutHelper helper = new TimeoutHelper(timeout);
                channel.Open(helper.RemainingTime());
                using (Message message = this.CreateRequest(operation, target, currentToken, out obj2))
                {
                    TraceUtility.ProcessOutgoingMessage(message);
                    using (Message message2 = channel.Request(message, helper.RemainingTime()))
                    {
                        if (message2 == null)
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("FailToRecieveReplyFromNegotiation")));
                        }
                        TraceUtility.ProcessIncomingMessage(message2);
                        ThrowIfFault(message2, this.targetAddress);
                        token = this.ProcessReply(message2, operation, obj2);
                        this.ValidateKeySize(token);
                    }
                }
                channel.Close(helper.RemainingTime());
                this.OnOperationSuccess(operation, target, token, currentToken);
                token2 = token;
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                if (exception is TimeoutException)
                {
                    exception = new TimeoutException(System.ServiceModel.SR.GetString("ClientSecuritySessionRequestTimeout", new object[] { timeout }), exception);
                }
                this.OnOperationFailure(operation, target, currentToken, exception, channel);
                throw;
            }
            return(token2);
        }
        GenericXmlSecurityToken DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
        {
            if (target == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("target");
            }
            if (operation == SecuritySessionOperation.Renew && currentToken == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("currentToken");
            }
            IRequestChannel channel = null;

            try
            {
                SecurityTraceRecordHelper.TraceBeginSecuritySessionOperation(operation, target, currentToken);
                channel = this.CreateChannel(operation, target, via);

                TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
                channel.Open(timeoutHelper.RemainingTime());
                object requestState;
                GenericXmlSecurityToken issuedToken;

                using (Message requestMessage = this.CreateRequest(operation, target, currentToken, out requestState))
                {
                    EventTraceActivity eventTraceActivity = null;
                    if (TD.MessageReceivedFromTransportIsEnabled())
                    {
                        eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(requestMessage);
                    }

                    TraceUtility.ProcessOutgoingMessage(requestMessage, eventTraceActivity);

                    using (Message reply = channel.Request(requestMessage, timeoutHelper.RemainingTime()))
                    {
                        if (reply == null)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.FailToRecieveReplyFromNegotiation)));
                        }

                        if (eventTraceActivity == null && TD.MessageReceivedFromTransportIsEnabled())
                        {
                            eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(reply);
                        }

                        TraceUtility.ProcessIncomingMessage(reply, eventTraceActivity);
                        ThrowIfFault(reply, this.targetAddress);
                        issuedToken = ProcessReply(reply, operation, requestState);
                        ValidateKeySize(issuedToken);
                    }
                }
                channel.Close(timeoutHelper.RemainingTime());
                this.OnOperationSuccess(operation, target, issuedToken, currentToken);
                return(issuedToken);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                if (e is TimeoutException)
                {
                    e = new TimeoutException(SR.GetString(SR.ClientSecuritySessionRequestTimeout, timeout), e);
                }

                OnOperationFailure(operation, target, currentToken, e, channel);
                throw;
            }
        }