internal RequestContext ProcessReceivedRequest(RequestContext requestContext)
        {
            if (requestContext == null)
            {
                return(null);
            }
            Exception     securityException = null;
            TimeSpan      timeout           = ServiceDefaults.ReceiveTimeout;
            Message       message           = requestContext.RequestMessage;
            TimeoutHelper timeoutHelper     = new TimeoutHelper(timeout);

            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.Format(SR.ReceivedMessageInRequestContextNull)));
            }
            try
            {
                SecurityProtocolCorrelationState correlationState = VerifyIncomingMessage(ref message, timeoutHelper.RemainingTime(), null);
                if (message.Headers.RelatesTo == null && message.Headers.MessageId != null)
                {
                    message.Headers.RelatesTo = message.Headers.MessageId;
                }
                return(new SecurityRequestContext(message, requestContext, SecurityProtocol, correlationState, ServiceDefaults.SendTimeout, ServiceDefaults.CloseTimeout));
            }
            catch
            {
                SendFaultIfRequired(securityException, requestContext, timeoutHelper.RemainingTime());
                throw;
            }
        }
 internal Message ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
 {
     if (reply != null)
     {
         Message   unverifiedMessage = reply;
         Exception faultException    = null;
         try
         {
             SecurityProtocol.VerifyIncomingMessage(ref reply, timeout, correlationState);
         }
         catch (MessageSecurityException)
         {
             TryGetSecurityFaultException(unverifiedMessage, out faultException);
             if (faultException == null)
             {
                 throw;
             }
         }
         if (faultException != null)
         {
             Fault(faultException);
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(faultException);
         }
     }
     return(reply);
 }
 public SecurityRequestContext(Message requestMessage, RequestContext innerContext,
                               SecurityProtocol securityProtocol, SecurityProtocolCorrelationState correlationState,
                               TimeSpan defaultSendTimeout, TimeSpan defaultCloseTimeout)
     : base(requestMessage, defaultCloseTimeout, defaultSendTimeout)
 {
     _innerContext     = innerContext;
     _securityProtocol = securityProtocol;
     _correlationState = correlationState;
 }
示例#4
0
            public Message Request(Message message, TimeSpan timeout)
            {
                this.ThrowIfFaulted();
                this.ThrowIfDisposedOrNotOpen(message);
                TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
                SecurityProtocolCorrelationState correlationState = this.SecurityProtocol.SecureOutgoingMessage(ref message, timeoutHelper.RemainingTime(), (SecurityProtocolCorrelationState)null);

                return(this.ProcessReply(this.InnerChannel.Request(message, timeoutHelper.RemainingTime()), correlationState, timeoutHelper.RemainingTime()));
            }
示例#5
0
 internal Message ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
 {
     if (reply != null)
     {
         if (DiagnosticUtility.ShouldUseActivity)
         {
             ServiceModelActivity replyActivity = TraceUtility.ExtractActivity(reply);
             if (replyActivity != null &&
                 correlationState != null &&
                 correlationState.Activity != null &&
                 replyActivity.Id != correlationState.Activity.Id)
             {
                 using (ServiceModelActivity.BoundOperation(replyActivity))
                 {
                     if (null != FxTrace.Trace)
                     {
                         FxTrace.Trace.TraceTransfer(correlationState.Activity.Id);
                     }
                     replyActivity.Stop();
                 }
             }
         }
         ServiceModelActivity activity = correlationState == null ? null : correlationState.Activity;
         using (ServiceModelActivity.BoundOperation(activity))
         {
             if (DiagnosticUtility.ShouldUseActivity)
             {
                 TraceUtility.SetActivity(reply, activity);
             }
             Message   unverifiedMessage = reply;
             Exception faultException    = null;
             try
             {
                 this.SecurityProtocol.VerifyIncomingMessage(ref reply, timeout, correlationState);
             }
             catch (MessageSecurityException)
             {
                 TryGetSecurityFaultException(unverifiedMessage, out faultException);
                 if (faultException == null)
                 {
                     throw;
                 }
             }
             if (faultException != null)
             {
                 this.Fault(faultException);
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(faultException);
             }
         }
     }
     return(reply);
 }
示例#6
0
 internal Message ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
 {
     if (reply != null)
     {
         if (DiagnosticUtility.ShouldUseActivity)
         {
             ServiceModelActivity activity = TraceUtility.ExtractActivity(reply);
             if (((activity != null) && (correlationState != null)) && ((correlationState.Activity != null) && (activity.Id != correlationState.Activity.Id)))
             {
                 using (ServiceModelActivity.BoundOperation(activity))
                 {
                     if (FxTrace.Trace != null)
                     {
                         FxTrace.Trace.TraceTransfer(correlationState.Activity.Id);
                     }
                     activity.Stop();
                 }
             }
         }
         ServiceModelActivity activity2 = (correlationState == null) ? null : correlationState.Activity;
         using (ServiceModelActivity.BoundOperation(activity2))
         {
             if (DiagnosticUtility.ShouldUseActivity)
             {
                 TraceUtility.SetActivity(reply, activity2);
             }
             Message   faultMessage   = reply;
             Exception faultException = null;
             try
             {
                 base.SecurityProtocol.VerifyIncomingMessage(ref reply, timeout, new SecurityProtocolCorrelationState[] { correlationState });
             }
             catch (MessageSecurityException)
             {
                 base.TryGetSecurityFaultException(faultMessage, out faultException);
                 if (faultException == null)
                 {
                     throw;
                 }
             }
             if (faultException != null)
             {
                 base.Fault(faultException);
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(faultException);
             }
         }
     }
     return(reply);
 }