コード例 #1
0
 public static void Trace(TraceEventType type, int traceCode, string description)
 {
     if (DiagnosticUtility.ShouldTrace(type))
     {
         Guid empty             = Guid.Empty;
         Guid guid              = Guid.Empty;
         IComThreadingInfo info = (IComThreadingInfo)SafeNativeMethods.CoGetObjectContext(IID_IComThreadingInfo);
         if (info != null)
         {
             info.GetCurrentLogicalThreadId(out empty);
             IObjectContextInfo info2 = info as IObjectContextInfo;
             if (info2 != null)
             {
                 info2.GetActivityId(out guid);
             }
         }
         ComPlusActivitySchema schema = new ComPlusActivitySchema(guid, empty, Thread.CurrentThread.ManagedThreadId, SafeNativeMethods.GetCurrentThreadId());
         TraceUtility.TraceEvent(type, traceCode, System.ServiceModel.SR.GetString(description), (TraceRecord)schema);
     }
 }
コード例 #2
0
 public static void Trace(TraceEventType type, int traceCode, string description, ServiceInfo info, Uri from, string action, string callerIdentity, Guid iid, int instanceID, Guid incomingTransactionID, Guid currentTransactionID)
 {
     if (DiagnosticUtility.ShouldTrace(type))
     {
         ComPlusMethodCallTxMismatchSchema schema = new ComPlusMethodCallTxMismatchSchema(from, info.AppID, info.Clsid, iid, action, instanceID, Thread.CurrentThread.ManagedThreadId, SafeNativeMethods.GetCurrentThreadId(), callerIdentity, incomingTransactionID, currentTransactionID);
         TraceUtility.TraceEvent(type, traceCode, System.ServiceModel.SR.GetString(description), (TraceRecord)schema);
     }
 }
コード例 #3
0
 public static void Trace(TraceEventType type, int traceCode, string description, ServiceInfo info, Uri from, string action, string callerIdentity, Guid iid, int instanceID, bool traceContextTransaction)
 {
     if (DiagnosticUtility.ShouldTrace(type))
     {
         ComPlusMethodCallSchema schema = null;
         Guid empty = Guid.Empty;
         if (traceContextTransaction)
         {
             IComThreadingInfo info2 = (IComThreadingInfo)SafeNativeMethods.CoGetObjectContext(IID_IComThreadingInfo);
             if (info2 != null)
             {
                 IObjectContextInfo info3 = info2 as IObjectContextInfo;
                 if ((info3 != null) && info3.IsInTransaction())
                 {
                     info3.GetTransactionId(out empty);
                 }
             }
             if (empty != Guid.Empty)
             {
                 schema = new ComPlusMethodCallContextTxSchema(from, info.AppID, info.Clsid, iid, action, instanceID, Thread.CurrentThread.ManagedThreadId, SafeNativeMethods.GetCurrentThreadId(), callerIdentity, empty);
             }
         }
         else
         {
             schema = new ComPlusMethodCallSchema(from, info.AppID, info.Clsid, iid, action, instanceID, Thread.CurrentThread.ManagedThreadId, SafeNativeMethods.GetCurrentThreadId(), callerIdentity);
         }
         if (schema != null)
         {
             TraceUtility.TraceEvent(type, traceCode, System.ServiceModel.SR.GetString(description), (TraceRecord)schema);
         }
     }
 }
 public static void Trace(TraceEventType type, int traceCode, string description, ServiceInfo info, Uri from, string action, string callerIdentity,
                          Guid iid, int instanceID, bool traceContextTransaction)
 {
     if (DiagnosticUtility.ShouldTrace(type))
     {
         ComPlusMethodCallSchema record = null;
         Guid guidContextTrsansactionID = Guid.Empty;
         if (traceContextTransaction)
         {
             IComThreadingInfo comThreadingInfo;
             comThreadingInfo = (IComThreadingInfo)SafeNativeMethods.CoGetObjectContext(IID_IComThreadingInfo);
             if (comThreadingInfo != null)
             {
                 IObjectContextInfo contextInfo = comThreadingInfo as IObjectContextInfo;
                 if (contextInfo != null)
                 {
                     if (contextInfo.IsInTransaction())
                     {
                         contextInfo.GetTransactionId(out guidContextTrsansactionID);
                     }
                 }
             }
             if (guidContextTrsansactionID != Guid.Empty)
             {
                 record = new ComPlusMethodCallContextTxSchema(from, info.AppID, info.Clsid, iid, action,
                                                               instanceID, System.Threading.Thread.CurrentThread.ManagedThreadId, SafeNativeMethods.GetCurrentThreadId(), callerIdentity, guidContextTrsansactionID);
             }
         }
         else
         {
             record = new ComPlusMethodCallSchema(from, info.AppID, info.Clsid, iid, action,
                                                  instanceID, System.Threading.Thread.CurrentThread.ManagedThreadId, SafeNativeMethods.GetCurrentThreadId(), callerIdentity);
         }
         if (record != null)
         {
             TraceUtility.TraceEvent(type, traceCode, ServiceModelSR.GetString(description), record);
         }
     }
 }
 public static void Trace(TraceEventType type, int traceCode, string description)
 {
     if (DiagnosticUtility.ShouldTrace(type))
     {
         Guid guidLogicalThreadID = Guid.Empty;
         Guid guidActivityID      = Guid.Empty;
         IComThreadingInfo comThreadingInfo;
         comThreadingInfo = (IComThreadingInfo)SafeNativeMethods.CoGetObjectContext(IID_IComThreadingInfo);
         if (comThreadingInfo != null)
         {
             comThreadingInfo.GetCurrentLogicalThreadId(out guidLogicalThreadID);
             IObjectContextInfo contextInfo = comThreadingInfo as IObjectContextInfo;
             if (contextInfo != null)
             {
                 contextInfo.GetActivityId(out guidActivityID);
             }
         }
         ComPlusActivitySchema record =
             new ComPlusActivitySchema(guidActivityID, guidLogicalThreadID,
                                       System.Threading.Thread.CurrentThread.ManagedThreadId, SafeNativeMethods.GetCurrentThreadId());
         TraceUtility.TraceEvent(type, traceCode, ServiceModelSR.GetString(description), record);
     }
 }
コード例 #6
0
        public object BeforeInvoke(
            InstanceContext instanceContext,
            IClientChannel channel,
            Message message)
        {
            ComPlusServerSecurity       serverSecurity     = null;
            WindowsImpersonationContext impersonateContext = null;
            bool             errorTraced           = false;
            WindowsIdentity  identity              = null;
            Uri              from                  = null;
            object           instance              = null;
            int              instanceID            = 0;
            string           action                = null;
            TransactionProxy proxy                 = null;
            Transaction      tx                    = null;
            Guid             incomingTransactionID = Guid.Empty;

            // The outer try block is to comply with FXCOP's WrapVulnerableFinallyClausesInOuterTry rule.
            try
            {
                try
                {
                    identity = MessageUtil.GetMessageIdentity(message);

                    if (message.Headers.From != null)
                    {
                        from = message.Headers.From.Uri;
                    }

                    instance   = instanceContext.GetServiceInstance(message);
                    instanceID = instance.GetHashCode();
                    action     = message.Headers.Action;



                    ComPlusMethodCallTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationInvokingMethod,
                                                 SR.TraceCodeComIntegrationInvokingMethod, this.info, from, action, identity.Name, iid, instanceID, false);

                    // Security
                    //

                    if (this.info.CheckRoles)
                    {
                        if (!this.comAuth.IsAuthorizedForOperation(identity))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.CallAccessDenied());
                        }
                    }

                    if (this.info.HostingMode != HostingMode.WebHostOutOfProcess)
                    {
                        // NOTE: This has the side effect of setting up
                        //       the COM server security thing, so be sure
                        //       to clear it with Dispose() eventually.
                        //
                        serverSecurity = new ComPlusServerSecurity(identity,
                                                                   this.info.CheckRoles);
                    }

                    // Transactions
                    //
                    proxy = instanceContext.Extensions.Find <TransactionProxy>();
                    if (proxy != null)
                    {
                        // This makes the Tx header Understood.
                        tx = MessageUtil.GetMessageTransaction(message);
                        if (tx != null)
                        {
                            incomingTransactionID = tx.TransactionInformation.DistributedIdentifier;
                        }
                        try
                        {
                            if (tx != null)
                            {
                                proxy.SetTransaction(tx);
                            }
                            else
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.TransactionMismatch());
                            }
                            ComPlusMethodCallTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationInvokingMethodNewTransaction,
                                                         SR.TraceCodeComIntegrationInvokingMethodNewTransaction, this.info, from, action, identity.Name, iid, instanceID, incomingTransactionID);
                        }
                        catch (FaultException e)
                        {
                            Transaction txProxy = proxy.CurrentTransaction;
                            Guid        currentTransactionID = Guid.Empty;
                            if (txProxy != null)
                            {
                                currentTransactionID = txProxy.TransactionInformation.DistributedIdentifier;
                            }

                            string identityName = String.Empty;

                            if (null != identity)
                            {
                                identityName = identity.Name;
                            }

                            DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                                (ushort)System.Runtime.Diagnostics.EventLogCategory.ComPlus,
                                                                (uint)System.Runtime.Diagnostics.EventLogEventId.ComPlusInvokingMethodFailedMismatchedTransactions,
                                                                incomingTransactionID.ToString("B").ToUpperInvariant(),
                                                                currentTransactionID.ToString("B").ToUpperInvariant(),
                                                                from.ToString(),
                                                                this.info.AppID.ToString("B").ToUpperInvariant(),
                                                                this.info.Clsid.ToString("B").ToUpperInvariant(),
                                                                iid.ToString(),
                                                                action,
                                                                instanceID.ToString(CultureInfo.InvariantCulture),
                                                                System.Threading.Thread.CurrentThread.ManagedThreadId.ToString(CultureInfo.InvariantCulture),
                                                                SafeNativeMethods.GetCurrentThreadId().ToString(CultureInfo.InvariantCulture),
                                                                identityName,
                                                                e.ToString());
                            errorTraced = true;
                            throw;
                        }
                    }
                    else
                    {
                        ComPlusMethodCallTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationInvokingMethodContextTransaction,
                                                     SR.TraceCodeComIntegrationInvokingMethodContextTransaction, this.info, from, action, identity.Name, iid, instanceID, true);
                    }

                    // Impersonation
                    //
                    if (this.info.HostingMode == HostingMode.WebHostOutOfProcess)
                    {
                        impersonateContext = identity.Impersonate();
                    }

                    CorrelationState correlationState;
                    correlationState = new CorrelationState(impersonateContext,
                                                            serverSecurity,
                                                            from,
                                                            action,
                                                            identity.Name,
                                                            instanceID);

                    impersonateContext = null;
                    serverSecurity     = null;


                    return(correlationState);
                }
                finally
                {
                    if (impersonateContext != null)
                    {
                        impersonateContext.Undo();
                    }

                    if (serverSecurity != null)
                    {
                        ((IDisposable)serverSecurity).Dispose();
                    }
                }
            }
            catch (Exception e)
            {
                if (errorTraced == false)
                {
                    if (DiagnosticUtility.ShouldTraceError)
                    {
                        DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                            (ushort)System.Runtime.Diagnostics.EventLogCategory.ComPlus,
                                                            (uint)System.Runtime.Diagnostics.EventLogEventId.ComPlusInvokingMethodFailed,
                                                            from == null ? string.Empty : from.ToString(),
                                                            this.info.AppID.ToString("B").ToUpperInvariant(),
                                                            this.info.Clsid.ToString("B").ToUpperInvariant(),
                                                            iid.ToString("B").ToUpperInvariant(),
                                                            action,
                                                            instanceID.ToString(CultureInfo.InvariantCulture),
                                                            System.Threading.Thread.CurrentThread.ManagedThreadId.ToString(CultureInfo.InvariantCulture),
                                                            SafeNativeMethods.GetCurrentThreadId().ToString(CultureInfo.InvariantCulture),
                                                            identity.Name,
                                                            e.ToString());
                    }
                }
                throw;
            }
        }