示例#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 void WriteResponse(ServiceMethodInfo methodInfo, HttpResponse httpResponse, object response)
 {
     if (response != null)
     {
         if (methodInfo.IsStreamedResponse)
         {
             httpResponse.Buffer = false;
             Stream stream = response as Stream;
             stream.CopyTo(httpResponse.OutputStream);
             httpResponse.OutputStream.Flush();
             return;
         }
         if (methodInfo.IsWrappedResponse)
         {
             Dictionary <string, object> graph = new Dictionary <string, object>
             {
                 {
                     methodInfo.Name + "Result",
                     response
                 }
             };
             DataContractJsonSerializer dataContractJsonSerializer = OwaServiceMethodDispatcher.CreateSimpleDictionaryJsonSerializer(new Type[]
             {
                 response.GetType()
             });
             dataContractJsonSerializer.WriteObject(httpResponse.OutputStream, graph);
             return;
         }
         DataContractJsonSerializer dataContractJsonSerializer2 = OwaServiceMethodDispatcher.CreateJsonSerializer(methodInfo.ResponseType);
         dataContractJsonSerializer2.WriteObject(httpResponse.OutputStream, response);
     }
 }
示例#3
0
        private static object ReadJsonObject(Type objectType, Stream stream)
        {
            object result;

            try
            {
                DataContractJsonSerializer dataContractJsonSerializer = OwaServiceMethodDispatcher.CreateJsonSerializer(objectType);
                result = dataContractJsonSerializer.ReadObject(stream);
            }
            catch (SerializationException ex)
            {
                string arg = OwaServiceMethodDispatcher.TryGetJsonContentFromStream(stream, 2048);
                OwaServerTraceLogger.AppendToLog(new TraceLogEvent("OwaServiceMethodDispatcher", null, "ReadJsonObject", string.Format("Type: {0} Exception: {1}, JSON: {2}", objectType.Name, ex.Message, arg)));
                throw new OwaSerializationException(string.Format("Cannot deserialize object of type {0}", objectType.Name), ex);
            }
            return(result);
        }