internal static ComProxy Create(IntPtr outer, IProvideChannelBuilderSettings channelBuilderSettings)
        {
            if (channelBuilderSettings == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CannotCreateChannelOption)));
            }


            ChannelCredentials ChannelCredentials = null;
            ComProxy           proxy = null;

            try
            {
                ChannelCredentials = new ChannelCredentials(channelBuilderSettings);
                proxy = ComProxy.Create(outer, ChannelCredentials, ChannelCredentials);
                return(proxy);
            }
            finally
            {
                if (proxy == null)
                {
                    if (ChannelCredentials != null)
                    {
                        ((IDisposable)ChannelCredentials).Dispose();
                    }
                }
            }
        }
Example #2
0
        internal static ComProxy Create(IntPtr outer, IProvideChannelBuilderSettings channelBuilderSettings)
        {
            ComProxy proxy2;

            if (channelBuilderSettings == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CannotCreateChannelOption")));
            }
            ChannelCredentials credentials = null;
            ComProxy           proxy       = null;

            try
            {
                credentials = new ChannelCredentials(channelBuilderSettings);
                proxy       = ComProxy.Create(outer, credentials, credentials);
                proxy2      = proxy;
            }
            finally
            {
                if ((proxy == null) && (credentials != null))
                {
                    ((IDisposable)credentials).Dispose();
                }
            }
            return(proxy2);
        }
 ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
 {
     if ((riid != typeof(IMoniker).GUID) && (riid != typeof(IParseDisplayName).GUID))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(System.ServiceModel.SR.GetString("NoInterface", new object[] { (Guid) riid })));
     }
     if (outer == IntPtr.Zero)
     {
         throw Fx.AssertAndThrow("OuterProxy cannot be null");
     }
     if (this.comProxy == null)
     {
         ServiceMonikerInternal internal2 = null;
         try
         {
             internal2 = new ServiceMonikerInternal();
             this.comProxy = ComProxy.Create(outer, internal2, internal2);
             return this.comProxy;
         }
         finally
         {
             if ((this.comProxy == null) && (internal2 != null))
             {
                 ((IDisposable) internal2).Dispose();
             }
         }
     }
     return this.comProxy.Clone();
 }
 ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
 {
     if ((riid != typeof(IMoniker).GUID) && (riid != typeof(IParseDisplayName).GUID))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(System.ServiceModel.SR.GetString("NoInterface", new object[] { (Guid)riid })));
     }
     if (outer == IntPtr.Zero)
     {
         throw Fx.AssertAndThrow("OuterProxy cannot be null");
     }
     if (this.comProxy == null)
     {
         ServiceMonikerInternal internal2 = null;
         try
         {
             internal2     = new ServiceMonikerInternal();
             this.comProxy = ComProxy.Create(outer, internal2, internal2);
             return(this.comProxy);
         }
         finally
         {
             if ((this.comProxy == null) && (internal2 != null))
             {
                 ((IDisposable)internal2).Dispose();
             }
         }
     }
     return(this.comProxy.Clone());
 }
        ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
        {
            if ((riid != typeof(IMoniker).GUID) && (riid != typeof(IParseDisplayName).GUID))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(SR.GetString(SR.NoInterface, riid)));
            if (outer == IntPtr.Zero)
            {
                throw Fx.AssertAndThrow("OuterProxy cannot be null");
            }

            if (comProxy == null)
            {
                ServiceMonikerInternal moniker = null;
                try
                {
                    moniker = new ServiceMonikerInternal();
                    comProxy = ComProxy.Create(outer, moniker, moniker);
                    return comProxy;

                }
                finally
                {
                    if ((comProxy == null) && (moniker != null))
                        ((IDisposable)moniker).Dispose();

                }
            }
            else
                return comProxy.Clone();
        }
Example #6
0
        ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
        {
            ComProxy proxy3;

            if (outer == IntPtr.Zero)
            {
                throw Fx.AssertAndThrow("OuterProxy cannot be null");
            }
            if (this.contractType == null)
            {
                TypeCacheManager.Provider.FindOrCreateType(riid, out this.contractType, true, false);
            }
            if ((this.contractType.GUID != riid) && !this.CheckDispatch(ref riid))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(System.ServiceModel.SR.GetString("NoInterface", new object[] { (Guid)riid })));
            }
            System.Type  proxiedType = EmitterCache.TypeEmitter.FindOrCreateType(this.contractType);
            ComProxy     proxy       = null;
            TearOffProxy disp        = null;

            try
            {
                disp   = new TearOffProxy(this, proxiedType);
                proxy  = ComProxy.Create(outer, disp.GetTransparentProxy(), disp);
                proxy3 = proxy;
            }
            finally
            {
                if ((proxy == null) && (disp != null))
                {
                    ((IDisposable)disp).Dispose();
                }
            }
            return(proxy3);
        }
        internal static ComProxy Create(IntPtr outer, ContractDescription contract, IProvideChannelBuilderSettings channelBuilderSettings)
        {
            DispatchProxy proxy = null;
            IntPtr inner = IntPtr.Zero;
            ComProxy comProxy = null;
            try
            {
                proxy = new DispatchProxy(contract, channelBuilderSettings);
                inner = OuterProxyWrapper.CreateDispatchProxy(outer, proxy);
                comProxy = new ComProxy(inner, proxy);
                return comProxy;

            }
            finally
            {
                if (comProxy == null)
                {
                    if (proxy != null)
                    {
                        ((IDisposable)proxy).Dispose();
                    }
                    if (inner != IntPtr.Zero)
                    {
                        Marshal.Release(inner);
                    }
                }

            }


        }
Example #8
0
        internal static ComProxy Create(IntPtr outer, ContractDescription contract, IProvideChannelBuilderSettings channelBuilderSettings)
        {
            DispatchProxy proxy = null;
            ComProxy      proxy3;
            IntPtr        zero   = IntPtr.Zero;
            ComProxy      proxy2 = null;

            try
            {
                proxy  = new DispatchProxy(contract, channelBuilderSettings);
                zero   = OuterProxyWrapper.CreateDispatchProxy(outer, proxy);
                proxy2 = new ComProxy(zero, proxy);
                proxy3 = proxy2;
            }
            finally
            {
                if (proxy2 == null)
                {
                    if (proxy != null)
                    {
                        ((IDisposable)proxy).Dispose();
                    }
                    if (zero != IntPtr.Zero)
                    {
                        Marshal.Release(zero);
                    }
                }
            }
            return(proxy3);
        }
        internal static ComProxy Create(IntPtr outer, ContractDescription contract, IProvideChannelBuilderSettings channelBuilderSettings)
        {
            DispatchProxy proxy    = null;
            IntPtr        inner    = IntPtr.Zero;
            ComProxy      comProxy = null;

            try
            {
                proxy    = new DispatchProxy(contract, channelBuilderSettings);
                inner    = OuterProxyWrapper.CreateDispatchProxy(outer, proxy);
                comProxy = new ComProxy(inner, proxy);
                return(comProxy);
            }
            finally
            {
                if (comProxy == null)
                {
                    if (proxy != null)
                    {
                        ((IDisposable)proxy).Dispose();
                    }
                    if (inner != IntPtr.Zero)
                    {
                        Marshal.Release(inner);
                    }
                }
            }
        }
 internal static ComProxy Create(IntPtr outer, ContractDescription contract, IProvideChannelBuilderSettings channelBuilderSettings)
 {
     DispatchProxy proxy = null;
     ComProxy proxy3;
     IntPtr zero = IntPtr.Zero;
     ComProxy proxy2 = null;
     try
     {
         proxy = new DispatchProxy(contract, channelBuilderSettings);
         zero = OuterProxyWrapper.CreateDispatchProxy(outer, proxy);
         proxy2 = new ComProxy(zero, proxy);
         proxy3 = proxy2;
     }
     finally
     {
         if (proxy2 == null)
         {
             if (proxy != null)
             {
                 ((IDisposable) proxy).Dispose();
             }
             if (zero != IntPtr.Zero)
             {
                 Marshal.Release(zero);
             }
         }
     }
     return proxy3;
 }
Example #11
0
        ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
        {
            if ((riid != typeof(IMoniker).GUID) && (riid != typeof(IParseDisplayName).GUID))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(SR.GetString(SR.NoInterface, riid)));
            }
            if (outer == IntPtr.Zero)
            {
                throw Fx.AssertAndThrow("OuterProxy cannot be null");
            }

            if (comProxy == null)
            {
                ServiceMonikerInternal moniker = null;
                try
                {
                    moniker  = new ServiceMonikerInternal();
                    comProxy = ComProxy.Create(outer, moniker, moniker);
                    return(comProxy);
                }
                finally
                {
                    if ((comProxy == null) && (moniker != null))
                    {
                        ((IDisposable)moniker).Dispose();
                    }
                }
            }
            else
            {
                return(comProxy.Clone());
            }
        }
Example #12
0
        int IProxyManager.Invoke(
            UInt32 dispIdMember,
            IntPtr outerProxy,
            IntPtr pVarResult,
            IntPtr pExcepInfo

            )
        {
            try
            {
                ComProxy comProxy = null;
                Guid     riid;
                if ((dispIdMember == 1))
                {
                    riid = typeof(IChannelOptions).GUID;
                }
                else if ((dispIdMember == 2))
                {
                    riid = typeof(IChannelCredentials).GUID;
                }
                else
                {
                    return(HR.DISP_E_MEMBERNOTFOUND);
                }
                FindOrCreateProxyInternal(outerProxy, ref riid, out comProxy);
                TagVariant variant = new TagVariant();
                variant.vt = (ushort)VarEnum.VT_DISPATCH;
                IntPtr tearOffDispatch = IntPtr.Zero;
                comProxy.QueryInterface(ref riid, out tearOffDispatch);
                variant.ptr = tearOffDispatch;
                Marshal.StructureToPtr(variant, pVarResult, true);
                return(HR.S_OK);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                if (pExcepInfo != IntPtr.Zero)
                {
                    System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO();
                    e = e.GetBaseException();
                    exceptionInfo.bstrDescription = e.Message;
                    exceptionInfo.bstrSource      = e.Source;
                    exceptionInfo.scode           = Marshal.GetHRForException(e);
                    Marshal.StructureToPtr(exceptionInfo, pExcepInfo, false);
                }
                return(HR.DISP_E_EXCEPTION);
            }
        }
 ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
 {
     if (riid != typeof(ITransactionProxy).GUID)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(System.ServiceModel.SR.GetString("NoInterface", new object[] { (Guid) riid })));
     }
     if (outer == IntPtr.Zero)
     {
         DiagnosticUtility.FailFast("OuterProxy cannot be null");
     }
     if (this.comProxy == null)
     {
         this.comProxy = ComProxy.Create(outer, this.txProxy, null);
         return this.comProxy;
     }
     return this.comProxy.Clone();
 }
 ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
 {
     if (riid != typeof(ITransactionProxy).GUID)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(System.ServiceModel.SR.GetString("NoInterface", new object[] { (Guid)riid })));
     }
     if (outer == IntPtr.Zero)
     {
         DiagnosticUtility.FailFast("OuterProxy cannot be null");
     }
     if (this.comProxy == null)
     {
         this.comProxy = ComProxy.Create(outer, this.txProxy, null);
         return(this.comProxy);
     }
     return(this.comProxy.Clone());
 }
Example #15
0
 int IProxyManager.Invoke(uint dispIdMember, IntPtr outerProxy, IntPtr pVarResult, IntPtr pExcepInfo)
 {
     try
     {
         Guid     gUID;
         ComProxy comProxy = null;
         if (dispIdMember == 1)
         {
             gUID = typeof(IChannelOptions).GUID;
         }
         else if (dispIdMember == 2)
         {
             gUID = typeof(IChannelCredentials).GUID;
         }
         else
         {
             return(HR.DISP_E_MEMBERNOTFOUND);
         }
         this.FindOrCreateProxyInternal(outerProxy, ref gUID, out comProxy);
         TagVariant structure = new TagVariant {
             vt = 9
         };
         IntPtr zero = IntPtr.Zero;
         comProxy.QueryInterface(ref gUID, out zero);
         structure.ptr = zero;
         Marshal.StructureToPtr(structure, pVarResult, true);
         return(HR.S_OK);
     }
     catch (Exception baseException)
     {
         if (Fx.IsFatal(baseException))
         {
             throw;
         }
         if (pExcepInfo != IntPtr.Zero)
         {
             System.Runtime.InteropServices.ComTypes.EXCEPINFO excepinfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO();
             baseException             = baseException.GetBaseException();
             excepinfo.bstrDescription = baseException.Message;
             excepinfo.bstrSource      = baseException.Source;
             excepinfo.scode           = Marshal.GetHRForException(baseException);
             Marshal.StructureToPtr(excepinfo, pExcepInfo, false);
         }
         return(HR.DISP_E_EXCEPTION);
     }
 }
Example #16
0
 int IProxyManager.FindOrCreateProxy(IntPtr outerProxy, ref Guid riid, out IntPtr tearOff)
 {
     tearOff = IntPtr.Zero;
     try
     {
         ComProxy comProxy = null;
         this.FindOrCreateProxyInternal(outerProxy, ref riid, out comProxy);
         comProxy.QueryInterface(ref riid, out tearOff);
         return(HR.S_OK);
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         return(Marshal.GetHRForException(exception.GetBaseException()));
     }
 }
 void FindOrCreateProxyInternal(IntPtr outerProxy, ref Guid riid, out ComProxy comProxy)
 {
     comProxy = null;
     lock (this)
     {
         InterfaceIDToComProxy.TryGetValue(riid, out comProxy);
         if (comProxy == null)
         {
             if (IsIntrinsic(ref riid))
                 comProxy = GenerateIntrinsic(outerProxy, ref riid);
             else
                 comProxy = CreateServiceChannel(outerProxy, ref riid);
             InterfaceIDToComProxy[riid] = comProxy;
         }
     }
     if (comProxy == null)
     {
         throw Fx.AssertAndThrow("comProxy should not be null at this point");
     }
 }
Example #18
0
        ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
        {
            if ((riid != typeof(ITransactionProxy).GUID))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(SR.GetString(SR.NoInterface, riid)));
            }
            if (outer == IntPtr.Zero)
            {
                // transactions require failfasts to prevent corruption
                DiagnosticUtility.FailFast("OuterProxy cannot be null");
            }

            if (comProxy == null)
            {
                comProxy = ComProxy.Create(outer, txProxy, null);
                return(comProxy);
            }
            else
            {
                return(comProxy.Clone());
            }
        }
Example #19
0
 void FindOrCreateProxyInternal(IntPtr outerProxy, ref Guid riid, out ComProxy comProxy)
 {
     comProxy = null;
     lock (this)
     {
         InterfaceIDToComProxy.TryGetValue(riid, out comProxy);
         if (comProxy == null)
         {
             if (IsIntrinsic(ref riid))
             {
                 comProxy = GenerateIntrinsic(outerProxy, ref riid);
             }
             else
             {
                 comProxy = CreateServiceChannel(outerProxy, ref riid);
             }
             InterfaceIDToComProxy[riid] = comProxy;
         }
     }
     if (comProxy == null)
     {
         throw Fx.AssertAndThrow("comProxy should not be null at this point");
     }
 }
Example #20
0
        ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
        {
            if (outer == IntPtr.Zero)
            {
                throw Fx.AssertAndThrow("OuterProxy cannot be null");
            }

            // No contract Fault on in
            if (contractType == null)
            {
                TypeCacheManager.Provider.FindOrCreateType(riid, out contractType, true, false);
            }

            if ((contractType.GUID != riid) && !(CheckDispatch(ref riid)))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(SR.GetString(SR.NoInterface, riid)));
            }

            Type         proxiedType  = EmitterCache.TypeEmitter.FindOrCreateType(contractType);
            ComProxy     comProxy     = null;
            TearOffProxy tearoffProxy = null;

            try
            {
                tearoffProxy = new TearOffProxy(this, proxiedType);
                comProxy     = ComProxy.Create(outer, tearoffProxy.GetTransparentProxy(), tearoffProxy);
                return(comProxy);
            }
            finally
            {
                if ((comProxy == null) && (tearoffProxy != null))
                {
                    ((IDisposable)tearoffProxy).Dispose();
                }
            }
        }