internal static object CreateProxy <TChannel>(MessageDirection direction, ServiceChannel serviceChannel)
        {
            if (!typeof(TChannel).IsInterface())
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SRServiceModel.SFxChannelFactoryTypeMustBeInterface));
            }

            return(ServiceChannelProxy.CreateProxy <TChannel>(direction, serviceChannel));
        }
        internal static object CreateProxy(Type interfaceType, Type proxiedType, MessageDirection direction, ServiceChannel serviceChannel)
        {
            if (!proxiedType.IsInterface)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString("SFxChannelFactoryTypeMustBeInterface")));
            }
            ServiceChannelProxy proxy = new ServiceChannelProxy(interfaceType, proxiedType, direction, serviceChannel);

            return(proxy.GetTransparentProxy());
        }
Beispiel #3
0
        internal static ServiceChannel GetServiceChannel(object transparentProxy)
        {
            IChannelBaseProxy proxy = transparentProxy as IChannelBaseProxy;

            if (proxy != null)
            {
                return(proxy.GetServiceChannel());
            }
            ServiceChannelProxy realProxy = RemotingServices.GetRealProxy(transparentProxy) as ServiceChannelProxy;

            if (realProxy != null)
            {
                return(realProxy.GetServiceChannel());
            }
            return(null);
        }
Beispiel #4
0
        // ServiceChannelProxy serves 2 roles.  It is the TChannel proxy called by the client,
        // and it is also the handler of those calls that dispatches them to the appropriate service channel.
        // In .Net Remoting terms, it is conceptually the same as a RealProxy and a TransparentProxy combined.
        internal static TChannel CreateProxy <TChannel>(MessageDirection direction, ServiceChannel serviceChannel)
        {
            TChannel proxy = DispatchProxy.Create <TChannel, ServiceChannelProxy>();

            if (proxy == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.FailedToCreateTypedProxy, typeof(TChannel))));
            }

            ServiceChannelProxy channelProxy = (ServiceChannelProxy)(object)proxy;

            channelProxy._proxiedType     = typeof(TChannel);
            channelProxy._serviceChannel  = serviceChannel;
            channelProxy._proxyRuntime    = serviceChannel.ClientRuntime.GetRuntime();
            channelProxy._methodDataCache = new MethodDataCache();
            return(proxy);
        }
        internal static ServiceChannel GetServiceChannel(object transparentProxy)
        {
            IChannelBaseProxy cb = transparentProxy as IChannelBaseProxy;

            if (cb != null)
            {
                return(cb.GetServiceChannel());
            }

            ServiceChannelProxy proxy = transparentProxy as ServiceChannelProxy;

            if (proxy != null)
            {
                return(proxy.GetServiceChannel());
            }
            else
            {
                return(null);
            }
        }
 public bool TryGetMethodData(MethodBase method, out ServiceChannelProxy.MethodData methodData)
 {
     lock (this.ThisLock)
     {
         ServiceChannelProxy.MethodData[] methodDatas = this.methodDatas;
         int index = FindMethod(methodDatas, method);
         if (index >= 0)
         {
             methodData = methodDatas[index];
             return true;
         }
         methodData = new ServiceChannelProxy.MethodData();
         return false;
     }
 }
 public void SetMethodData(ServiceChannelProxy.MethodData methodData)
 {
     lock (this.ThisLock)
     {
         if (FindMethod(this.methodDatas, methodData.MethodBase) < 0)
         {
             for (int i = 0; i < this.methodDatas.Length; i++)
             {
                 if (this.methodDatas[i].MethodBase == null)
                 {
                     this.methodDatas[i] = methodData;
                     goto Label_00B5;
                 }
             }
             ServiceChannelProxy.MethodData[] destinationArray = new ServiceChannelProxy.MethodData[this.methodDatas.Length * 2];
             Array.Copy(this.methodDatas, destinationArray, this.methodDatas.Length);
             destinationArray[this.methodDatas.Length] = methodData;
             this.methodDatas = destinationArray;
         }
     Label_00B5:;
     }
 }
 private static int FindMethod(ServiceChannelProxy.MethodData[] methodDatas, MethodBase methodToFind)
 {
     for (int i = 0; i < methodDatas.Length; i++)
     {
         MethodBase methodBase = methodDatas[i].MethodBase;
         if (methodBase == null)
         {
             break;
         }
         if (methodBase == methodToFind)
         {
             return i;
         }
     }
     return -1;
 }