Ejemplo n.º 1
0
 internal WebServiceMethodData(WebServiceData owner, string methodName, Dictionary <string, WebServiceParameterData> parameterData, bool useHttpGet)
 {
     this._owner         = owner;
     this._methodName    = methodName;
     this._parameterData = parameterData;
     this._useHttpGet    = new bool?(useHttpGet);
 }
Ejemplo n.º 2
0
 // Methods
 internal static string GetClientTypeFromServerType(WebServiceData webServiceData, Type type)
 {
     if (webServiceData.ClientTypeNameDictionary.ContainsKey(type))
     {
         return(webServiceData.ClientTypeNameDictionary[type]);
     }
     if (type.IsEnum)
     {
         return(GetClientTypeName(type.FullName));
     }
     if ((type == typeof(string)) || (type == typeof(char)))
     {
         return("String");
     }
     if (type.IsPrimitive)
     {
         if (type == typeof(bool))
         {
             return("Boolean");
         }
         return("Number");
     }
     if (type.IsValueType)
     {
         if (type == typeof(DateTime))
         {
             return("Date");
         }
         if (type == typeof(Guid))
         {
             return("String");
         }
         if (type == typeof(decimal))
         {
             return("Number");
         }
     }
     if (typeof(IDictionary).IsAssignableFrom(type))
     {
         return("Object");
     }
     if (type.IsGenericType)
     {
         Type genericTypeDefinition = type;
         if (!type.IsGenericTypeDefinition)
         {
             genericTypeDefinition = type.GetGenericTypeDefinition();
         }
         if (genericTypeDefinition == typeof(IDictionary <,>))
         {
             return("Object");
         }
     }
     if (!type.IsArray && !typeof(IEnumerable).IsAssignableFrom(type))
     {
         return("");
     }
     return("Array");
 }
Ejemplo n.º 3
0
        // Methods
        internal static IHttpHandler CreateHandler(HttpContext context)
        {
            if ((context.Request.PathInfo.Length < 2) || (context.Request.PathInfo[0] != '/'))
            {
                throw new InvalidOperationException("WebService_InvalidWebServiceCall");
            }
            WebServiceData webServiceData = WebServiceData.GetWebServiceData(context, context.Request.FilePath);
            string         methodName     = context.Request.PathInfo.Substring(1);

            return(CreateHandler(webServiceData, methodName));
        }
Ejemplo n.º 4
0
        internal static WebServiceData GetWebServiceData(ContractDescription contract)
        {
            WebServiceData owner = new WebServiceData
            {
                _typeData = new WebServiceTypeData(XmlConvert.DecodeName(contract.Name), XmlConvert.DecodeName(contract.Namespace), contract.ContractType)
            };
            Dictionary <string, WebServiceTypeData> dictionary = new Dictionary <string, WebServiceTypeData>();

            owner._clientTypesDictionary = dictionary;
            Dictionary <string, WebServiceEnumData> dictionary2 = new Dictionary <string, WebServiceEnumData>();

            owner._enumTypesDictionary      = dictionary2;
            owner._processedTypes           = new Hashtable();
            owner._clientTypesProcessed     = true;
            owner._clientTypeNameDictionary = new Dictionary <Type, string>();
            Dictionary <string, WebServiceMethodData> dictionary3 = new Dictionary <string, WebServiceMethodData>();

            owner._methods = dictionary3;
            foreach (OperationDescription description in contract.Operations)
            {
                Dictionary <string, WebServiceParameterData> parameterData = new Dictionary <string, WebServiceParameterData>();
                bool useHttpGet                   = description.Behaviors.Find <WebGetAttribute>() != null;
                WebServiceMethodData data2        = new WebServiceMethodData(owner, XmlConvert.DecodeName(description.Name), parameterData, useHttpGet);
                MessageDescription   description2 = description.Messages[0];
                if (description2 != null)
                {
                    int count = description2.Body.Parts.Count;
                    for (int j = 0; j < count; j++)
                    {
                        MessagePartDescription description3 = description2.Body.Parts[j];
                        Type paramType = ReplaceMessageWithObject(description3.Type);
                        WebServiceParameterData data3 = new WebServiceParameterData(XmlConvert.DecodeName(description3.Name), paramType, j);
                        parameterData[data3.ParameterName] = data3;
                        owner.ProcessClientType(paramType, false, true);
                    }
                }
                if (description.Messages.Count > 1)
                {
                    MessageDescription description4 = description.Messages[1];
                    if (((description4 != null) && (description4.Body.ReturnValue != null)) && (description4.Body.ReturnValue.Type != null))
                    {
                        owner.ProcessClientType(ReplaceMessageWithObject(description4.Body.ReturnValue.Type), false, true);
                    }
                }
                for (int i = 0; i < description.KnownTypes.Count; i++)
                {
                    owner.ProcessClientType(description.KnownTypes[i], false, true);
                }
                dictionary3[data2.MethodName] = data2;
            }
            owner._processedTypes = null;
            return(owner);
        }
Ejemplo n.º 5
0
 // Methods
 internal WebServiceMethodData(WebServiceData owner, MethodInfo methodInfo, WebMethodAttribute webMethodAttribute, ScriptMethodAttribute scriptMethodAttribute)
 {
     this._owner                 = owner;
     this._methodInfo            = methodInfo;
     this._webMethodAttribute    = webMethodAttribute;
     this._methodName            = this._webMethodAttribute.MessageName;
     this._scriptMethodAttribute = scriptMethodAttribute;
     if (string.IsNullOrEmpty(this._methodName))
     {
         this._methodName = methodInfo.Name;
     }
 }
Ejemplo n.º 6
0
        private static IHttpHandler CreateHandler(WebServiceData webServiceData, string methodName)
        {
            RestHandler          handler;
            WebServiceMethodData methodData = webServiceData.GetMethodData(methodName);

            if (methodData.RequiresSession)
            {
                handler = new RestHandlerWithSession();
            }
            else
            {
                handler = new RestHandler();
            }
            handler._webServiceMethodData = methodData;
            return(handler);
        }
Ejemplo n.º 7
0
        internal static WebServiceData GetWebServiceData(HttpContext context, string virtualPath, bool failIfNoData, bool pageMethods, bool inlineScript)
        {
            virtualPath = VirtualPathUtility.ToAbsolute(virtualPath);
            string         cacheKey           = GetCacheKey(virtualPath);
            WebServiceData applicationService = context.Cache[cacheKey] as WebServiceData;

            if (applicationService == null)
            {
                if (HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))
                {
                    Type compiledType = null;
                    try
                    {
                        compiledType = BuildManager.GetCompiledType(virtualPath);
                        if (compiledType == null)
                        {
                            object obj2 = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(Page));
                            if (obj2 != null)
                            {
                                compiledType = obj2.GetType();
                            }
                        }
                    }
                    catch (SecurityException)
                    {
                    }
                    if (compiledType != null)
                    {
                        applicationService = new WebServiceData(compiledType, pageMethods);
                        IEnumerable virtualPaths = BuildManager.GetCachedBuildDependencySet(context, virtualPath).VirtualPaths;
                        if (virtualPaths != null)
                        {
                            List <string> list    = new List <string>();
                            HttpRequest   request = context.Request;
                            foreach (string str2 in virtualPaths)
                            {
                                list.Add(request.MapPath(str2));
                            }
                            context.Cache.Insert(cacheKey, applicationService, new CacheDependency(list.ToArray()));
                        }
                        else
                        {
                            context.Cache.Insert(cacheKey, applicationService);
                        }
                    }
                }
                else if (virtualPath.EndsWith("_AppService.axd", StringComparison.OrdinalIgnoreCase))
                {
                    applicationService = GetApplicationService(context.Request.AppRelativeCurrentExecutionFilePath);
                    if (applicationService != null)
                    {
                        context.Cache.Insert(cacheKey, applicationService);
                    }
                }
            }
            if (applicationService != null)
            {
                return(applicationService);
            }
            if (!failIfNoData)
            {
                return(null);
            }
            if (inlineScript)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "NoWebServiceDataInlineScript", new object[] { virtualPath }));
            }
            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "NoWebServiceData", new object[] { virtualPath }));
        }