internal static void GenerateXmlMappings(Type type, ArrayList soapMethodList, string serviceNamespace, bool serviceDefaultIsEncoded, ArrayList mappings)
        {
            LogicalMethodInfo[] methodInfos = LogicalMethodInfo.Create(type.GetMethods(BindingFlags.Public | BindingFlags.Instance), LogicalMethodTypes.Sync);

            SoapReflectionImporter soapImporter = SoapReflector.CreateSoapImporter(serviceNamespace, serviceDefaultIsEncoded);
            XmlReflectionImporter  xmlImporter  = SoapReflector.CreateXmlImporter(serviceNamespace, serviceDefaultIsEncoded);

            WebMethodReflector.IncludeTypes(methodInfos, xmlImporter);
            SoapReflector.IncludeTypes(methodInfos, soapImporter);


            for (int i = 0; i < methodInfos.Length; i++)
            {
                LogicalMethodInfo   methodInfo = methodInfos[i];
                SoapReflectedMethod soapMethod = SoapReflector.ReflectMethod(methodInfo, true, xmlImporter, soapImporter, serviceNamespace);
                if (soapMethod == null)
                {
                    continue;
                }
                soapMethodList.Add(soapMethod);
                mappings.Add(soapMethod.requestMappings);
                if (soapMethod.responseMappings != null)
                {
                    mappings.Add(soapMethod.responseMappings);
                }
                mappings.Add(soapMethod.inHeaderMappings);
                if (soapMethod.outHeaderMappings != null)
                {
                    mappings.Add(soapMethod.outHeaderMappings);
                }
            }
        }
Пример #2
0
        internal HttpClientType(Type type)
        {
            LogicalMethodInfo[] infoArray      = LogicalMethodInfo.Create(type.GetMethods(), LogicalMethodTypes.Sync);
            Hashtable           formatterTypes = new Hashtable();

            for (int i = 0; i < infoArray.Length; i++)
            {
                LogicalMethodInfo info = infoArray[i];
                try
                {
                    object[] customAttributes = info.GetCustomAttributes(typeof(HttpMethodAttribute));
                    if (customAttributes.Length != 0)
                    {
                        HttpMethodAttribute attribute = (HttpMethodAttribute)customAttributes[0];
                        HttpClientMethod    method    = new HttpClientMethod {
                            readerType = attribute.ReturnFormatter,
                            writerType = attribute.ParameterFormatter,
                            methodInfo = info
                        };
                        AddFormatter(formatterTypes, method.readerType, method);
                        AddFormatter(formatterTypes, method.writerType, method);
                        this.methods.Add(info.Name, method);
                    }
                }
                catch (Exception exception)
                {
                    if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                    {
                        throw;
                    }
                    throw new InvalidOperationException(Res.GetString("WebReflectionError", new object[] { info.DeclaringType.FullName, info.Name }), exception);
                }
            }
            foreach (Type type2 in formatterTypes.Keys)
            {
                ArrayList           list        = (ArrayList)formatterTypes[type2];
                LogicalMethodInfo[] methodInfos = new LogicalMethodInfo[list.Count];
                for (int j = 0; j < list.Count; j++)
                {
                    methodInfos[j] = ((HttpClientMethod)list[j]).methodInfo;
                }
                object[] initializers = MimeFormatter.GetInitializers(type2, methodInfos);
                bool     flag         = typeof(MimeParameterWriter).IsAssignableFrom(type2);
                for (int k = 0; k < list.Count; k++)
                {
                    if (flag)
                    {
                        ((HttpClientMethod)list[k]).writerInitializer = initializers[k];
                    }
                    else
                    {
                        ((HttpClientMethod)list[k]).readerInitializer = initializers[k];
                    }
                }
            }
        }
        internal HttpClientType(Type type)
        {
            LogicalMethodInfo[] methodInfos = LogicalMethodInfo.Create(type.GetMethods(), LogicalMethodTypes.Sync);

            Hashtable formatterTypes = new Hashtable();

            for (int i = 0; i < methodInfos.Length; i++)
            {
                LogicalMethodInfo methodInfo = methodInfos[i];
                try {
                    object[] attributes = methodInfo.GetCustomAttributes(typeof(HttpMethodAttribute));
                    if (attributes.Length == 0)
                    {
                        continue;
                    }
                    HttpMethodAttribute attribute = (HttpMethodAttribute)attributes[0];
                    HttpClientMethod    method    = new HttpClientMethod();
                    method.readerType = attribute.ReturnFormatter;
                    method.writerType = attribute.ParameterFormatter;
                    method.methodInfo = methodInfo;
                    AddFormatter(formatterTypes, method.readerType, method);
                    AddFormatter(formatterTypes, method.writerType, method);
                    methods.Add(methodInfo.Name, method);
                }
                catch (Exception e) {
                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                    {
                        throw;
                    }
                    throw new InvalidOperationException(Res.GetString(Res.WebReflectionError, methodInfo.DeclaringType.FullName, methodInfo.Name), e);
                }
            }

            foreach (Type t in formatterTypes.Keys)
            {
                ArrayList           list = (ArrayList)formatterTypes[t];
                LogicalMethodInfo[] m    = new LogicalMethodInfo[list.Count];
                for (int j = 0; j < list.Count; j++)
                {
                    m[j] = ((HttpClientMethod)list[j]).methodInfo;
                }
                object[] initializers = MimeFormatter.GetInitializers(t, m);
                bool     isWriter     = typeof(MimeParameterWriter).IsAssignableFrom(t);
                for (int j = 0; j < list.Count; j++)
                {
                    if (isWriter)
                    {
                        ((HttpClientMethod)list[j]).writerInitializer = initializers[j];
                    }
                    else
                    {
                        ((HttpClientMethod)list[j]).readerInitializer = initializers[j];
                    }
                }
            }
        }
Пример #4
0
        internal SoapClientType(Type type)
        {
            LogicalMethodInfo[] methodInfos    = LogicalMethodInfo.Create(type.GetMethods(BindingFlags.Public | BindingFlags.Instance), LogicalMethodTypes.Sync);
            ArrayList           mappings       = new ArrayList();
            ArrayList           soapMethodList = new ArrayList();

            this.binding = WebServiceBindingReflector.GetAttribute(type);
            if (this.binding == null)
            {
                throw new InvalidOperationException(Res.GetString(Res.WebClientBindingAttributeRequired));
            }
            // Note: Service namespace is taken from WebserviceBindingAttribute and not WebserviceAttribute because
            // the generated proxy does not have a WebServiceAttribute; however all have a WebServiceBindingAttribute.
            serviceNamespace        = binding.Namespace;
            serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(type);
            SoapReflectionImporter soapImporter = SoapReflector.CreateSoapImporter(serviceNamespace, serviceDefaultIsEncoded);
            XmlReflectionImporter  xmlImporter  = SoapReflector.CreateXmlImporter(serviceNamespace, serviceDefaultIsEncoded);

            WebMethodReflector.IncludeTypes(methodInfos, xmlImporter);
            SoapReflector.IncludeTypes(methodInfos, soapImporter);

            SoapExtensionType[] extensionTypes = WebServicesConfiguration.Current.SoapExtensionTypes;
            ArrayList           highPri        = new ArrayList();
            ArrayList           lowPri         = new ArrayList();

            for (int i = 0; i < extensionTypes.Length; i++)
            {
                SoapReflectedExtension extension = new SoapReflectedExtension(extensionTypes[i].Type, null, extensionTypes[i].Priority);
                if (extensionTypes[i].Group == SoapExtensionType.PriorityGroup.High)
                {
                    highPri.Add(extension);
                }
                else
                {
                    lowPri.Add(extension);
                }
            }
            HighPriExtensions = (SoapReflectedExtension[])highPri.ToArray(typeof(SoapReflectedExtension));
            LowPriExtensions  = (SoapReflectedExtension[])lowPri.ToArray(typeof(SoapReflectedExtension));
            Array.Sort(HighPriExtensions);
            Array.Sort(LowPriExtensions);
            HighPriExtensionInitializers = SoapReflectedExtension.GetInitializers(type, HighPriExtensions);
            LowPriExtensionInitializers  = SoapReflectedExtension.GetInitializers(type, LowPriExtensions);

            for (int i = 0; i < methodInfos.Length; i++)
            {
                LogicalMethodInfo   methodInfo = methodInfos[i];
                SoapReflectedMethod soapMethod = SoapReflector.ReflectMethod(methodInfo, true, xmlImporter, soapImporter, serviceNamespace);
                if (soapMethod == null)
                {
                    continue;
                }
                soapMethodList.Add(soapMethod);
                mappings.Add(soapMethod.requestMappings);
                if (soapMethod.responseMappings != null)
                {
                    mappings.Add(soapMethod.responseMappings);
                }
                mappings.Add(soapMethod.inHeaderMappings);
                if (soapMethod.outHeaderMappings != null)
                {
                    mappings.Add(soapMethod.outHeaderMappings);
                }
            }

            XmlSerializer[] serializers = XmlSerializer.FromMappings((XmlMapping[])mappings.ToArray(typeof(XmlMapping)));
            int             count       = 0;

            for (int i = 0; i < soapMethodList.Count; i++)
            {
                SoapReflectedMethod soapMethod   = (SoapReflectedMethod)soapMethodList[i];
                SoapClientMethod    clientMethod = new SoapClientMethod();
                clientMethod.parameterSerializer = serializers[count++];
                if (soapMethod.responseMappings != null)
                {
                    clientMethod.returnSerializer = serializers[count++];
                }
                clientMethod.inHeaderSerializer = serializers[count++];
                if (soapMethod.outHeaderMappings != null)
                {
                    clientMethod.outHeaderSerializer = serializers[count++];
                }
                clientMethod.action                = soapMethod.action;
                clientMethod.oneWay                = soapMethod.oneWay;
                clientMethod.rpc                   = soapMethod.rpc;
                clientMethod.use                   = soapMethod.use;
                clientMethod.paramStyle            = soapMethod.paramStyle;
                clientMethod.methodInfo            = soapMethod.methodInfo;
                clientMethod.extensions            = soapMethod.extensions;
                clientMethod.extensionInitializers = SoapReflectedExtension.GetInitializers(clientMethod.methodInfo, soapMethod.extensions);
                ArrayList inHeaders  = new ArrayList();
                ArrayList outHeaders = new ArrayList();
                for (int j = 0; j < soapMethod.headers.Length; j++)
                {
                    SoapHeaderMapping   mapping    = new SoapHeaderMapping();
                    SoapReflectedHeader soapHeader = soapMethod.headers[j];
                    mapping.memberInfo = soapHeader.memberInfo;
                    mapping.repeats    = soapHeader.repeats;
                    mapping.custom     = soapHeader.custom;
                    mapping.direction  = soapHeader.direction;
                    mapping.headerType = soapHeader.headerType;
                    if ((mapping.direction & SoapHeaderDirection.In) != 0)
                    {
                        inHeaders.Add(mapping);
                    }
                    if ((mapping.direction & (SoapHeaderDirection.Out | SoapHeaderDirection.Fault)) != 0)
                    {
                        outHeaders.Add(mapping);
                    }
                }
                clientMethod.inHeaderMappings = (SoapHeaderMapping[])inHeaders.ToArray(typeof(SoapHeaderMapping));
                if (clientMethod.outHeaderSerializer != null)
                {
                    clientMethod.outHeaderMappings = (SoapHeaderMapping[])outHeaders.ToArray(typeof(SoapHeaderMapping));
                }
                methods.Add(soapMethod.name, clientMethod);
            }
        }
Пример #5
0
        public LogicalTypeInfo(Type t)
        {
            this.Type = t;

            object [] o = Type.GetCustomAttributes(typeof(WebServiceAttribute), false);
            if (o.Length == 1)
            {
                WebServiceAttribute a = (WebServiceAttribute)o [0];
                WebServiceName      = (a.Name != string.Empty) ? a.Name : Type.Name;
                WebServiceNamespace = (a.Namespace != string.Empty) ? a.Namespace : WebServiceAttribute.DefaultNamespace;
                Description         = a.Description;
            }
            else
            {
                WebServiceName      = Type.Name;
                WebServiceNamespace = WebServiceAttribute.DefaultNamespace;
            }

            // Determine the namespaces for literal and encoded schema types

            bindingUse = SoapBindingUse.Literal;

            o = t.GetCustomAttributes(typeof(SoapDocumentServiceAttribute), true);
            if (o.Length > 0)
            {
                SoapDocumentServiceAttribute at = (SoapDocumentServiceAttribute)o[0];
                bindingUse = at.Use;
                if (bindingUse == SoapBindingUse.Default)
                {
                    bindingUse = SoapBindingUse.Literal;
                }
                routingStyle = at.RoutingStyle;
            }
            else if (t.GetCustomAttributes(typeof(SoapRpcServiceAttribute), true).Length > 0)
            {
                o = t.GetCustomAttributes(typeof(SoapRpcServiceAttribute), true);
                SoapRpcServiceAttribute at = (SoapRpcServiceAttribute)o[0];
#if NET_2_0
                bindingUse = at.Use;
#else
                bindingUse = SoapBindingUse.Encoded;
#endif
                routingStyle = at.RoutingStyle;
                if (bindingUse == SoapBindingUse.Default)
                {
                    bindingUse = SoapBindingUse.Encoded;
                }
            }
            else
            {
                routingStyle = SoapServiceRoutingStyle.SoapAction;
            }
            string sep = WebServiceNamespace.EndsWith("/") ? "" : "/";

            WebServiceAbstractNamespace = WebServiceNamespace + sep + "AbstractTypes";
#if NET_2_0
            MethodInfo [] type_methods;
            if (typeof(WebClientProtocol).IsAssignableFrom(Type))
            {
                type_methods = Type.GetMethods(BindingFlags.Instance | BindingFlags.Public);
            }
            else
            {
                MethodInfo [] all_type_methods = Type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                ArrayList     list             = new ArrayList(all_type_methods.Length);
                foreach (MethodInfo mi in all_type_methods)
                {
                    if (mi.IsPublic && mi.GetCustomAttributes(typeof(WebMethodAttribute), false).Length > 0)
                    {
                        list.Add(mi);
                    }
                    else
                    {
                        foreach (Type ifaceType in Type.GetInterfaces())
                        {
                            if (ifaceType.GetCustomAttributes(typeof(WebServiceBindingAttribute), false).Length > 0)
                            {
                                MethodInfo found = FindInInterface(ifaceType, mi);
                                if (found != null)
                                {
                                    if (found.GetCustomAttributes(typeof(WebMethodAttribute), false).Length > 0)
                                    {
                                        list.Add(found);
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
                type_methods = (MethodInfo [])list.ToArray(typeof(MethodInfo));
            }
#else
            MethodInfo [] type_methods = Type.GetMethods(BindingFlags.Instance | BindingFlags.Public);
#endif
            logicalMethods = LogicalMethodInfo.Create(type_methods, LogicalMethodTypes.Sync);
        }