Ejemplo n.º 1
0
        private MethodData GetMethodData(MethodCall methodCall)
        {
            MethodBase method = methodCall.MethodBase;

            if (_methodDataCache.TryGetMethodData(method, out MethodData methodData))
            {
                return(methodData);
            }

            bool canCacheMessageData;

            Type declaringType = method.DeclaringType;

            if (declaringType == typeof(object) && method == typeof(object).GetMethod("GetType"))
            {
                canCacheMessageData = true;
                methodData          = new MethodData(method, MethodType.GetType);
            }
            else if (declaringType.IsAssignableFrom(_serviceChannel.GetType()))
            {
                canCacheMessageData = true;
                methodData          = new MethodData(method, MethodType.Channel);
            }
            else
            {
                ProxyOperationRuntime operation = _proxyRuntime.GetOperation(method, methodCall.Args, out canCacheMessageData);

                if (operation == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.SFxMethodNotSupportedOnCallback1, method.Name)));
                }

                MethodType methodType;

                if (operation.IsTaskCall(methodCall))
                {
                    methodType = MethodType.TaskService;
                }
                else if (operation.IsSyncCall(methodCall))
                {
                    methodType = MethodType.Service;
                }
                else if (operation.IsBeginCall(methodCall))
                {
                    methodType = MethodType.BeginService;
                }
                else
                {
                    methodType = MethodType.EndService;
                }

                methodData = new MethodData(method, methodType, operation);
            }

            if (canCacheMessageData)
            {
                _methodDataCache.SetMethodData(methodData);
            }

            return(methodData);
        }
        private MethodData GetMethodData(IMethodCallMessage methodCall)
        {
            MethodData data;
            MethodBase methodBase = methodCall.MethodBase;

            if (!this.methodDataCache.TryGetMethodData(methodBase, out data))
            {
                bool        flag;
                System.Type declaringType = methodBase.DeclaringType;
                if (declaringType == typeof(object))
                {
                    MethodType getType;
                    if (methodCall.MethodBase == typeof(object).GetMethod("GetType"))
                    {
                        getType = MethodType.GetType;
                    }
                    else
                    {
                        getType = MethodType.Object;
                    }
                    flag = true;
                    data = new MethodData(methodBase, getType);
                }
                else if (declaringType.IsInstanceOfType(this.serviceChannel))
                {
                    flag = true;
                    data = new MethodData(methodBase, MethodType.Channel);
                }
                else
                {
                    MethodType            service;
                    ProxyOperationRuntime operation = this.proxyRuntime.GetOperation(methodBase, methodCall.Args, out flag);
                    if (operation == null)
                    {
                        if (this.serviceChannel.Factory != null)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.ServiceModel.SR.GetString("SFxMethodNotSupported1", new object[] { methodBase.Name })));
                        }
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.ServiceModel.SR.GetString("SFxMethodNotSupportedOnCallback1", new object[] { methodBase.Name })));
                    }
                    if (operation.IsSyncCall(methodCall))
                    {
                        service = MethodType.Service;
                    }
                    else if (operation.IsBeginCall(methodCall))
                    {
                        service = MethodType.BeginService;
                    }
                    else
                    {
                        service = MethodType.EndService;
                    }
                    data = new MethodData(methodBase, service, operation);
                }
                if (flag)
                {
                    this.methodDataCache.SetMethodData(data);
                }
            }
            return(data);
        }
Ejemplo n.º 3
0
        MethodData GetMethodData(IMethodCallMessage methodCall)
        {
            MethodBase method = methodCall.MethodBase;

            MethodData methodData;

            if (methodDataCache.TryGetMethodData(method, out methodData))
            {
                return(methodData);
            }

            bool canCacheMessageData;

            Type declaringType = method.DeclaringType;

            if (declaringType == typeof(object))
            {
                MethodType methodType;
                if (methodCall.MethodBase == typeof(object).GetMethod("GetType"))
                {
                    methodType = MethodType.GetType;
                }
                else
                {
                    methodType = MethodType.Object;
                }
                canCacheMessageData = true;
                methodData          = new MethodData(method, methodType);
            }
            else if (declaringType.IsInstanceOfType(this.serviceChannel))
            {
                canCacheMessageData = true;
                methodData          = new MethodData(method, MethodType.Channel);
            }
            else
            {
                ProxyOperationRuntime operation = this.proxyRuntime.GetOperation(method, methodCall.Args, out canCacheMessageData);

                if (operation == null)
                {
                    if (this.serviceChannel.Factory != null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.SFxMethodNotSupported1, method.Name)));
                    }
                    else
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.SFxMethodNotSupportedOnCallback1, method.Name)));
                    }
                }

                MethodType methodType;

                if (operation.IsTaskCall(methodCall))
                {
                    methodType = MethodType.TaskService;
                }
                else if (operation.IsSyncCall(methodCall))
                {
                    methodType = MethodType.Service;
                }
                else if (operation.IsBeginCall(methodCall))
                {
                    methodType = MethodType.BeginService;
                }
                else
                {
                    methodType = MethodType.EndService;
                }

                methodData = new MethodData(method, methodType, operation);
            }

            if (canCacheMessageData)
            {
                methodDataCache.SetMethodData(methodData);
            }

            return(methodData);
        }