Ejemplo n.º 1
0
        internal static object[] GetInitializers(LogicalMethodInfo[] methodInfos)
        {
            if (methodInfos.Length == 0)
            {
                return(new object[0]);
            }
            WebServiceAttribute attribute  = WebServiceReflector.GetAttribute(methodInfos);
            bool serviceDefaultIsEncoded   = SoapReflector.ServiceDefaultIsEncoded(WebServiceReflector.GetMostDerivedType(methodInfos));
            XmlReflectionImporter importer = SoapReflector.CreateXmlImporter(attribute.Namespace, serviceDefaultIsEncoded);

            WebMethodReflector.IncludeTypes(methodInfos, importer);
            ArrayList list = new ArrayList();

            bool[] flagArray = new bool[methodInfos.Length];
            for (int i = 0; i < methodInfos.Length; i++)
            {
                LogicalMethodInfo methodInfo = methodInfos[i];
                Type returnType = methodInfo.ReturnType;
                if (IsSupported(returnType) && HttpServerProtocol.AreUrlParametersSupported(methodInfo))
                {
                    XmlAttributes  attributes = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider);
                    XmlTypeMapping mapping    = importer.ImportTypeMapping(returnType, attributes.XmlRoot);
                    mapping.SetKey(methodInfo.GetKey() + ":Return");
                    list.Add(mapping);
                    flagArray[i] = true;
                }
            }
            if (list.Count == 0)
            {
                return(new object[0]);
            }
            XmlMapping[] mappings        = (XmlMapping[])list.ToArray(typeof(XmlMapping));
            Evidence     evidenceForType = GetEvidenceForType(methodInfos[0].DeclaringType);
            TraceMethod  caller          = Tracing.On ? new TraceMethod(typeof(XmlReturn), "GetInitializers", methodInfos) : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId("TraceCreateSerializer"), caller, new TraceMethod(typeof(XmlSerializer), "FromMappings", new object[] { mappings, evidenceForType }));
            }
            XmlSerializer[] serializerArray = null;
            if (AppDomain.CurrentDomain.IsHomogenous)
            {
                serializerArray = XmlSerializer.FromMappings(mappings);
            }
            else
            {
                serializerArray = XmlSerializer.FromMappings(mappings, evidenceForType);
            }
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId("TraceCreateSerializer"), caller);
            }
            object[] objArray = new object[methodInfos.Length];
            int      num2     = 0;

            for (int j = 0; j < objArray.Length; j++)
            {
                if (flagArray[j])
                {
                    objArray[j] = serializerArray[num2++];
                }
            }
            return(objArray);
        }
        internal static object[] GetInitializers(LogicalMethodInfo[] methodInfos)
        {
            if (methodInfos.Length == 0)
            {
                return(new object[0]);
            }
            WebServiceAttribute serviceAttribute = WebServiceReflector.GetAttribute(methodInfos);
            bool serviceDefaultIsEncoded         = SoapReflector.ServiceDefaultIsEncoded(WebServiceReflector.GetMostDerivedType(methodInfos));
            XmlReflectionImporter importer       = SoapReflector.CreateXmlImporter(serviceAttribute.Namespace, serviceDefaultIsEncoded);

            WebMethodReflector.IncludeTypes(methodInfos, importer);
            ArrayList mappings = new ArrayList();

            bool[] supported = new bool[methodInfos.Length];
            for (int i = 0; i < methodInfos.Length; i++)
            {
                LogicalMethodInfo methodInfo = methodInfos[i];
                Type type = methodInfo.ReturnType;
                if (IsSupported(type) && HttpServerProtocol.AreUrlParametersSupported(methodInfo))
                {
                    XmlAttributes  a       = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider);
                    XmlTypeMapping mapping = importer.ImportTypeMapping(type, a.XmlRoot);
                    mapping.SetKey(methodInfo.GetKey() + ":Return");
                    mappings.Add(mapping);
                    supported[i] = true;
                }
            }
            if (mappings.Count == 0)
            {
                return(new object[0]);
            }

            XmlMapping[] xmlMappings = (XmlMapping[])mappings.ToArray(typeof(XmlMapping));
            Evidence     evidence    = GetEvidenceForType(methodInfos[0].DeclaringType);

            TraceMethod caller = Tracing.On ? new TraceMethod(typeof(XmlReturn), "GetInitializers", methodInfos) : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId(Res.TraceCreateSerializer), caller, new TraceMethod(typeof(XmlSerializer), "FromMappings", xmlMappings, evidence));
            }
            XmlSerializer[] serializers = null;
            if (AppDomain.CurrentDomain.IsHomogenous)
            {
                serializers = XmlSerializer.FromMappings(xmlMappings);
            }
            else
            {
#pragma warning disable 618 // If we're in a non-homogenous domain, legacy CAS mode is enabled, so passing through evidence will not fail
                serializers = XmlSerializer.FromMappings(xmlMappings, evidence);
#pragma warning restore 618
            }

            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId(Res.TraceCreateSerializer), caller);
            }

            object[] initializers = new object[methodInfos.Length];
            int      count        = 0;
            for (int i = 0; i < initializers.Length; i++)
            {
                if (supported[i])
                {
                    initializers[i] = serializers[count++];
                }
            }
            return(initializers);
        }