当前位置: 首页>>代码示例>>C#>>正文


C# InstanceContext.GetServiceInstance方法代码示例

本文整理汇总了C#中System.ServiceModel.InstanceContext.GetServiceInstance方法的典型用法代码示例。如果您正苦于以下问题:C# InstanceContext.GetServiceInstance方法的具体用法?C# InstanceContext.GetServiceInstance怎么用?C# InstanceContext.GetServiceInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ServiceModel.InstanceContext的用法示例。


在下文中一共展示了InstanceContext.GetServiceInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeforeInvoke

        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(),
//.........这里部分代码省略.........
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:101,代码来源:ComPlusThreadInitializer.cs

示例2: BeforeInvoke

 public object BeforeInvoke(InstanceContext instanceContext, IClientChannel channel, Message message)
 {
     ComPlusServerSecurity serverSecurity = null;
     WindowsImpersonationContext context = null;
     object obj3;
     bool flag = false;
     WindowsIdentity clientIdentity = null;
     Uri from = null;
     int instanceID = 0;
     string action = null;
     TransactionProxy proxy = null;
     Transaction messageTransaction = null;
     Guid empty = Guid.Empty;
     try
     {
         try
         {
             clientIdentity = MessageUtil.GetMessageIdentity(message);
             if (message.Headers.From != null)
             {
                 from = message.Headers.From.Uri;
             }
             instanceID = instanceContext.GetServiceInstance(message).GetHashCode();
             action = message.Headers.Action;
             ComPlusMethodCallTrace.Trace(TraceEventType.Verbose, 0x50018, "TraceCodeComIntegrationInvokingMethod", this.info, from, action, clientIdentity.Name, this.iid, instanceID, false);
             if (this.info.CheckRoles && !this.comAuth.IsAuthorizedForOperation(clientIdentity))
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.CallAccessDenied());
             }
             if (this.info.HostingMode != HostingMode.WebHostOutOfProcess)
             {
                 serverSecurity = new ComPlusServerSecurity(clientIdentity, this.info.CheckRoles);
             }
             proxy = instanceContext.Extensions.Find<TransactionProxy>();
             if (proxy != null)
             {
                 messageTransaction = MessageUtil.GetMessageTransaction(message);
                 if (messageTransaction != null)
                 {
                     empty = messageTransaction.TransactionInformation.DistributedIdentifier;
                 }
                 try
                 {
                     if (messageTransaction == null)
                     {
                         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.TransactionMismatch());
                     }
                     proxy.SetTransaction(messageTransaction);
                     ComPlusMethodCallTrace.Trace(TraceEventType.Verbose, 0x5001a, "TraceCodeComIntegrationInvokingMethodNewTransaction", this.info, from, action, clientIdentity.Name, this.iid, instanceID, empty);
                     goto Label_02DC;
                 }
                 catch (FaultException exception)
                 {
                     Transaction currentTransaction = proxy.CurrentTransaction;
                     Guid distributedIdentifier = Guid.Empty;
                     if (currentTransaction != null)
                     {
                         distributedIdentifier = currentTransaction.TransactionInformation.DistributedIdentifier;
                     }
                     string name = string.Empty;
                     if (clientIdentity != null)
                     {
                         name = clientIdentity.Name;
                     }
                     DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.ComPlus, (EventLogEventId) (-1073610725), new string[] { empty.ToString("B").ToUpperInvariant(), distributedIdentifier.ToString("B").ToUpperInvariant(), from.ToString(), this.info.AppID.ToString("B").ToUpperInvariant(), this.info.Clsid.ToString("B").ToUpperInvariant(), this.iid.ToString(), action, instanceID.ToString(CultureInfo.InvariantCulture), Thread.CurrentThread.ManagedThreadId.ToString(CultureInfo.InvariantCulture), System.ServiceModel.ComIntegration.SafeNativeMethods.GetCurrentThreadId().ToString(CultureInfo.InvariantCulture), name, exception.ToString() });
                     flag = true;
                     throw;
                 }
             }
             ComPlusMethodCallTrace.Trace(TraceEventType.Verbose, 0x5001b, "TraceCodeComIntegrationInvokingMethodContextTransaction", this.info, from, action, clientIdentity.Name, this.iid, instanceID, true);
         Label_02DC:
             if (this.info.HostingMode == HostingMode.WebHostOutOfProcess)
             {
                 context = clientIdentity.Impersonate();
             }
             CorrelationState state = new CorrelationState(context, serverSecurity, from, action, clientIdentity.Name, instanceID);
             context = null;
             serverSecurity = null;
             obj3 = state;
         }
         finally
         {
             if (context != null)
             {
                 context.Undo();
             }
             if (serverSecurity != null)
             {
                 ((IDisposable) serverSecurity).Dispose();
             }
         }
     }
     catch (Exception exception2)
     {
         if (!flag && DiagnosticUtility.ShouldTraceError)
         {
             DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.ComPlus, (EventLogEventId) (-1073610727), new string[] { (from == null) ? string.Empty : from.ToString(), this.info.AppID.ToString("B").ToUpperInvariant(), this.info.Clsid.ToString("B").ToUpperInvariant(), this.iid.ToString("B").ToUpperInvariant(), action, instanceID.ToString(CultureInfo.InvariantCulture), Thread.CurrentThread.ManagedThreadId.ToString(CultureInfo.InvariantCulture), System.ServiceModel.ComIntegration.SafeNativeMethods.GetCurrentThreadId().ToString(CultureInfo.InvariantCulture), clientIdentity.Name, exception2.ToString() });
         }
         throw;
     }
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:ComPlusThreadInitializer.cs


注:本文中的System.ServiceModel.InstanceContext.GetServiceInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。