예제 #1
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);
     }
 }
예제 #2
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));
        }