예제 #1
0
        private static void InitializeCachePolicy(WebServiceMethodData methodData, HttpContext context)
        {
            int cacheDuration = methodData.CacheDuration;

            if (cacheDuration > 0)
            {
                context.Response.Cache.SetCacheability(HttpCacheability.Server);
                context.Response.Cache.SetExpires(DateTime.Now.AddSeconds((double)cacheDuration));
                context.Response.Cache.SetSlidingExpiration(false);
                context.Response.Cache.SetValidUntilExpires(true);
                if (methodData.ParameterDatas.Count > 0)
                {
                    context.Response.Cache.VaryByParams["*"] = true;
                }
                else
                {
                    context.Response.Cache.VaryByParams.IgnoreParams = true;
                }
            }
            else
            {
                context.Response.Cache.SetNoServerCaching();
                context.Response.Cache.SetMaxAge(TimeSpan.Zero);
            }
        }
예제 #2
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);
        }
예제 #3
0
        internal WebServiceMethodData GetMethodData(string methodName)
        {
            this.EnsureMethods();
            WebServiceMethodData data = null;

            if (!this._methods.TryGetValue(methodName, out data))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "UnknownWebMethod", new object[] { methodName }), "methodName");
            }
            this.EnsureClientTypesProcessed();
            return(data);
        }
예제 #4
0
 private void AddMethod(Dictionary <string, WebServiceMethodData> methods, MethodInfo method)
 {
     object[] customAttributes = method.GetCustomAttributes(typeof(WebMethodAttribute), true);
     if (customAttributes.Length != 0)
     {
         ScriptMethodAttribute scriptMethodAttribute = null;
         object[] objArray2 = method.GetCustomAttributes(typeof(ScriptMethodAttribute), true);
         if (objArray2.Length > 0)
         {
             scriptMethodAttribute = (ScriptMethodAttribute)objArray2[0];
         }
         WebServiceMethodData data = new WebServiceMethodData(this, method, (WebMethodAttribute)customAttributes[0], scriptMethodAttribute);
         methods[data.MethodName] = data;
     }
 }
예제 #5
0
 private static IDictionary <string, object> GetRawParams(WebServiceMethodData methodData, HttpContext context)
 {
     if (methodData.UseGet)
     {
         if (context.Request.HttpMethod != "GET")
         {
             throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "WebService_InvalidVerbRequest", new object[] { methodData.MethodName, "POST" }));
         }
         return(GetRawParamsFromGetRequest(context, methodData.Owner.Serializer, methodData));
     }
     if (context.Request.HttpMethod != "POST")
     {
         throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "WebService_InvalidVerbRequest", new object[] { methodData.MethodName, "GET" }));
     }
     return(GetRawParamsFromPostRequest(context, methodData.Owner.Serializer));
 }
예제 #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);
        }
예제 #7
0
 internal static void ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)
 {
     try
     {
         //NamedPermissionSet namedPermissionSet = HttpRuntime.NamedPermissionSet;
         //if (namedPermissionSet != null)
         //{
         //    namedPermissionSet.PermitOnly();
         //}
         IDictionary <string, object> rawParams = GetRawParams(methodData, context);
         InvokeMethod(context, methodData, rawParams);
     }
     catch (Exception exception)
     {
         WriteExceptionJsonString(context, exception);
     }
 }
예제 #8
0
        private static void InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary <string, object> rawParams)
        {
            string str;

            InitializeCachePolicy(methodData, context);
            object target = null;

            if (!methodData.IsStatic)
            {
                target = Activator.CreateInstance(methodData.Owner.TypeData.Type);
            }
            object obj3 = methodData.CallMethodFromRawParams(target, rawParams);
            string s    = null;

            if (methodData.UseXmlResponse)
            {
                s = obj3 as string;
                if ((s == null) || methodData.XmlSerializeString)
                {
                    try
                    {
                        s = ServicesUtilities.XmlSerializeObjectToString(obj3);
                    }
                    catch (Exception exception)
                    {
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "WebService_InvalidXmlReturnType", new object[] { methodData.MethodName, obj3.GetType().FullName, exception.Message }));
                    }
                }
                str = "text/xml";
            }
            else
            {
                s   = "{\"d\":" + methodData.Owner.Serializer.Serialize(obj3) + "}";
                str = "application/json";
            }
            context.Response.ContentType = str;
            if (s != null)
            {
                context.Response.Write(s);
            }
        }
예제 #9
0
        private static IDictionary <string, object> GetRawParamsFromGetRequest(HttpContext context, JavaScriptSerializer serializer, WebServiceMethodData methodData)
        {
            NameValueCollection         queryString = context.Request.QueryString;
            Dictionary <string, object> dictionary  = new Dictionary <string, object>();

            foreach (WebServiceParameterData data in methodData.ParameterDatas)
            {
                string name  = data.ParameterInfo.Name;
                string input = queryString[name];
                if (input != null)
                {
                    dictionary.Add(name, serializer.DeserializeObject(input));
                }
            }
            return(dictionary);
        }