Exemplo n.º 1
0
 /// <summary>
 /// Gets the timeout by method.
 /// </summary>
 /// <param name="serviceContract">The service contract.</param>
 /// <param name="methodName">Name of the method.</param>
 /// <param name="parameterTypes">The parameter types.</param>
 /// <param name="timeoutType">Type of the timeout.</param>
 /// <returns></returns>
 protected long GetTimeoutByMethod(Type serviceContract, String methodName, MethodParameter[] parameterTypes, MethodTimeoutEnum timeoutType)
 {
     return(ServiceBase.GetTimeoutByMethod(serviceContract, methodName, parameterTypes, timeoutType));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the timeout by method.
        /// </summary>
        /// <param name="serviceContract">The service contract.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="parameterTypes">The parameter types.</param>
        /// <param name="timeoutType">Type of the timeout.</param>
        /// <returns>Timeout value</returns>
        /// <exception cref="Forge.Net.Remoting.InvalidProxyImplementationException">
        /// </exception>
        public static long GetTimeoutByMethod(Type serviceContract, String methodName, MethodParameter[] parameterTypes, MethodTimeoutEnum timeoutType)
        {
            long result = 0;

            Type[] pts = null;
            if (parameterTypes != null && parameterTypes.Length > 0)
            {
                pts = new Type[parameterTypes.Length];
                for (int i = 0; i < parameterTypes.Length; i++)
                {
                    try
                    {
                        pts[i] = TypeHelper.GetTypeFromString(parameterTypes[i].ClassName);
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidProxyImplementationException(String.Format("Provided parameter type '{0}' not resolved. This may be a proxy implementation error.", parameterTypes[i].ClassName), ex);
                    }
                }
            }
            try
            {
                MethodInfo m = ServiceBase.FindMethod(serviceContract, methodName, pts);
                OperationContractAttribute oc = TypeHelper.GetAttribute <OperationContractAttribute>(m);
                if (oc == null)
                {
                    // ez a metódus nem tartalmaz annotációt, ami csak akkor lehetséges, ha a proxy hibásan van generálva
                    throw new InvalidProxyImplementationException(String.Format("Provided method '{0}' found, but it has not got {1} annotation definition. This may be a proxy implementation error.", methodName, typeof(OperationContractAttribute).FullName));
                }
                else
                {
                    result = timeoutType == MethodTimeoutEnum.CallTimeout ? oc.CallTimeout : oc.ReturnTimeout;
                }
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                if (pts != null)
                {
                    foreach (Type c in pts)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(", ");
                        }
                        sb.Append(c.Name);
                    }
                    sb.Insert(0, String.Format(" Parameter types: ", pts.ToString()));
                }
                throw new InvalidProxyImplementationException(String.Format("Unable to find method name '{0}' with parameter types.{1}", methodName, sb.ToString()), ex);
            }

            return(result);
        }