コード例 #1
0
        public void ReleaseInstance(InstanceContext instanceContext, object instance)
        {
            int         hashCode   = instance.GetHashCode();
            IDisposable disposable = instance as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
            else
            {
                Marshal.ReleaseComObject(instance);
            }
            ComPlusInstanceCreationTrace.Trace(TraceEventType.Verbose, 0x50014, "TraceCodeComIntegrationInstanceReleased", this.info, instanceContext, hashCode);
        }
コード例 #2
0
        public void ReleaseInstance(InstanceContext instanceContext, object instance)
        {
            int         instanceID = instance.GetHashCode();
            IDisposable disposable = instance as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
            else
            {
                // All ServicedComponents are disposable, so we don't
                // have to worry about getting a ServicedComponent
                // here.
                //
                Marshal.ReleaseComObject(instance);
            }

            ComPlusInstanceCreationTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationInstanceReleased,
                                               SR.TraceCodeComIntegrationInstanceReleased, this.info, instanceContext, instanceID);
        }
コード例 #3
0
        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            object result = null;
            Guid   incomingTransactionID = Guid.Empty;

            if (ContextUtil.IsInTransaction)
            {
                incomingTransactionID = ContextUtil.TransactionId;
            }
            ComPlusInstanceCreationTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationInstanceCreationRequest,
                                               SR.TraceCodeComIntegrationInstanceCreationRequest, this.info, message, incomingTransactionID);

            WindowsIdentity callerIdentity = null;

            callerIdentity = MessageUtil.GetMessageIdentity(message);
            WindowsImpersonationContext impersonateContext = null;

            try
            {
                try
                {
                    if (this.info.HostingMode ==
                        HostingMode.WebHostOutOfProcess)
                    {
                        if (SecurityUtils.IsAtleastImpersonationToken(new SafeCloseHandle(callerIdentity.Token, false)))
                        {
                            impersonateContext = callerIdentity.Impersonate();
                        }
                        else
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(SR.GetString(SR.BadImpersonationLevelForOutOfProcWas), HR.ERROR_BAD_IMPERSONATION_LEVEL));
                        }
                    }

                    CLSCTX clsctx = CLSCTX.SERVER;
                    if (PlatformSupportsBitness && (this.info.HostingMode ==
                                                    HostingMode.WebHostOutOfProcess))
                    {
                        if (this.info.Bitness == Bitness.Bitness32)
                        {
                            clsctx |= CLSCTX.ACTIVATE_32_BIT_SERVER;
                        }
                        else
                        {
                            clsctx |= CLSCTX.ACTIVATE_64_BIT_SERVER;
                        }
                    }

                    result = SafeNativeMethods.CoCreateInstance(
                        info.Clsid,
                        null,
                        clsctx,
                        IID_IUnknown);
                }
                finally
                {
                    if (impersonateContext != null)
                    {
                        impersonateContext.Undo();
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

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

                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.ComPlus,
                                                    (uint)System.Runtime.Diagnostics.EventLogEventId.ComPlusInstanceCreationError,
                                                    from == null ? string.Empty : from.ToString(),
                                                    this.info.AppID.ToString(),
                                                    this.info.Clsid.ToString(),
                                                    incomingTransactionID.ToString(),
                                                    callerIdentity.Name,
                                                    e.ToString());

                throw TraceUtility.ThrowHelperError(e, message);
            }


            TransactionProxy proxy = instanceContext.Extensions.Find <TransactionProxy>();

            if (proxy != null)
            {
                proxy.InstanceID = result.GetHashCode();
            }

            ComPlusInstanceCreationTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationInstanceCreationSuccess,
                                               SR.TraceCodeComIntegrationInstanceCreationSuccess, this.info, message, result.GetHashCode(), incomingTransactionID);
            return(result);
        }
コード例 #4
0
        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            object obj2  = null;
            Guid   empty = Guid.Empty;

            if (ContextUtil.IsInTransaction)
            {
                empty = ContextUtil.TransactionId;
            }
            ComPlusInstanceCreationTrace.Trace(TraceEventType.Verbose, 0x50012, "TraceCodeComIntegrationInstanceCreationRequest", this.info, message, empty);
            WindowsIdentity messageIdentity = null;

            messageIdentity = MessageUtil.GetMessageIdentity(message);
            WindowsImpersonationContext context = null;

            try
            {
                try
                {
                    if (this.info.HostingMode == HostingMode.WebHostOutOfProcess)
                    {
                        if (!System.ServiceModel.ComIntegration.SecurityUtils.IsAtleastImpersonationToken(new SafeCloseHandle(messageIdentity.Token, false)))
                        {
                            throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(System.ServiceModel.SR.GetString("BadImpersonationLevelForOutOfProcWas"), HR.ERROR_BAD_IMPERSONATION_LEVEL));
                        }
                        context = messageIdentity.Impersonate();
                    }
                    CLSCTX sERVER = CLSCTX.SERVER;
                    if (PlatformSupportsBitness && (this.info.HostingMode == HostingMode.WebHostOutOfProcess))
                    {
                        if (this.info.Bitness == Bitness.Bitness32)
                        {
                            sERVER |= CLSCTX.ACTIVATE_32_BIT_SERVER;
                        }
                        else
                        {
                            sERVER |= CLSCTX.ACTIVATE_64_BIT_SERVER;
                        }
                    }
                    obj2 = System.ServiceModel.ComIntegration.SafeNativeMethods.CoCreateInstance(this.info.Clsid, null, sERVER, IID_IUnknown);
                }
                finally
                {
                    if (context != null)
                    {
                        context.Undo();
                    }
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                Uri uri = null;
                if (message.Headers.From != null)
                {
                    uri = message.Headers.From.Uri;
                }
                System.ServiceModel.DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.ComPlus, (EventLogEventId)(-1073610726), new string[] { (uri == null) ? string.Empty : uri.ToString(), this.info.AppID.ToString(), this.info.Clsid.ToString(), empty.ToString(), messageIdentity.Name, exception.ToString() });
                throw TraceUtility.ThrowHelperError(exception, message);
            }
            System.ServiceModel.ComIntegration.TransactionProxy proxy = instanceContext.Extensions.Find <System.ServiceModel.ComIntegration.TransactionProxy>();
            if (proxy != null)
            {
                proxy.InstanceID = obj2.GetHashCode();
            }
            ComPlusInstanceCreationTrace.Trace(TraceEventType.Verbose, 0x50013, "TraceCodeComIntegrationInstanceCreationSuccess", this.info, message, obj2.GetHashCode(), empty);
            return(obj2);
        }