예제 #1
0
        private static Dictionary <string, object> ConvertRequestToParameterDictionary(ServiceMethodInfo methodInfo, IEnumerable <ParameterInfo> parameters, Stream requestStream)
        {
            Type wrappedRequestType = methodInfo.WrappedRequestType;

            if (wrappedRequestType != null)
            {
                OwaServiceMethodDispatcher.CreateJsonSerializer(wrappedRequestType);
                object wrapperObject = OwaServiceMethodDispatcher.ReadJsonObject(wrappedRequestType, requestStream);
                return(OwaServiceMethodDispatcher.ConvertWrappedObjectToParameterDictionary(parameters, methodInfo.WrappedRequestTypeParameterMap, wrapperObject));
            }
            IEnumerable <Type> enumerable;

            if (parameters == null)
            {
                enumerable = null;
            }
            else
            {
                enumerable = parameters.ToList <ParameterInfo>().ConvertAll <Type>((ParameterInfo p) => p.ParameterType);
            }
            IEnumerable <Type>         knownTypes = enumerable;
            DataContractJsonSerializer dataContractJsonSerializer = OwaServiceMethodDispatcher.CreateSimpleDictionaryJsonSerializer(knownTypes);

            return((Dictionary <string, object>)dataContractJsonSerializer.ReadObject(requestStream));
        }
예제 #2
0
 private static object[] CreateMethodArgumentsFromRequest(ServiceMethodInfo methodInfo, HttpRequest httpRequest)
 {
     object[] result = null;
     if (methodInfo.IsWrappedRequest)
     {
         result = OwaServiceMethodDispatcher.CreateMethodArgumentsFromWrappedRequest(methodInfo, httpRequest);
     }
     else if (methodInfo.RequestType != null)
     {
         object obj = OwaServiceMethodDispatcher.ReadJsonObject(methodInfo.RequestType, httpRequest.InputStream);
         result = new object[]
         {
             obj
         };
     }
     return(result);
 }
예제 #3
0
 private static object ConvertStringToParameterValue(string strValue, ParameterInfo parameter)
 {
     try
     {
         if (parameter.ParameterType == typeof(string))
         {
             return(strValue);
         }
         if (parameter.ParameterType.IsEnum)
         {
             return(Enum.Parse(parameter.ParameterType, strValue));
         }
         if (parameter.ParameterType.IsValueType)
         {
             return(Convert.ChangeType(strValue, parameter.ParameterType));
         }
         string s = "\"" + strValue + "\"";
         using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(s)))
         {
             return(OwaServiceMethodDispatcher.ReadJsonObject(parameter.ParameterType, memoryStream));
         }
     }
     catch (InvalidCastException arg)
     {
         ExTraceGlobals.CoreTracer.TraceError <string, InvalidCastException>(0L, "Cast error occurred while converting string value to parameter {0}. Exception: {1}", parameter.Name, arg);
     }
     catch (FormatException arg2)
     {
         ExTraceGlobals.CoreTracer.TraceError <string, FormatException>(0L, "Format error occurred while converting string value to parameter {0}. Exception: {1}", parameter.Name, arg2);
     }
     catch (OverflowException arg3)
     {
         ExTraceGlobals.CoreTracer.TraceError <string, OverflowException>(0L, "Overflow error occurred while converting string value to parameter {0}. Exception: {1}", parameter.Name, arg3);
     }
     return(null);
 }