示例#1
0
        private void ImportHeaderSerializers(SoapReflectedMethod soapMethod)
        {
            List <SoapHeaderMapping> inHeaders  = new List <SoapHeaderMapping>();
            List <SoapHeaderMapping> outHeaders = new List <SoapHeaderMapping>();

            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)
                {
                    inHeaders.Add(mapping);
                }
                else if (mapping.direction == SoapHeaderDirection.Out)
                {
                    outHeaders.Add(mapping);
                }
                else
                {
                    inHeaders.Add(mapping);
                    outHeaders.Add(mapping);
                }
            }

            this.inHeaderMappings = inHeaders.ToArray();
            if (this.outHeaderSerializer != null)
            {
                this.outHeaderMappings = outHeaders.ToArray();
            }
        }
示例#2
0
        private void ImportHeaderSerializers(SoapReflectedMethod soapMethod)
        {
            List <SoapHeaderMapping> list  = new List <SoapHeaderMapping>();
            List <SoapHeaderMapping> list2 = new List <SoapHeaderMapping>();

            for (int i = 0; i < soapMethod.headers.Length; i++)
            {
                SoapHeaderMapping   item   = new SoapHeaderMapping();
                SoapReflectedHeader header = soapMethod.headers[i];
                item.memberInfo = header.memberInfo;
                item.repeats    = header.repeats;
                item.custom     = header.custom;
                item.direction  = header.direction;
                item.headerType = header.headerType;
                if (item.direction == SoapHeaderDirection.In)
                {
                    list.Add(item);
                }
                else if (item.direction == SoapHeaderDirection.Out)
                {
                    list2.Add(item);
                }
                else
                {
                    list.Add(item);
                    list2.Add(item);
                }
            }
            this.inHeaderMappings = list.ToArray();
            if (this.outHeaderSerializer != null)
            {
                this.outHeaderMappings = list2.ToArray();
            }
        }
        void CreateHeaderMessages(string methodName, SoapBindingUse use, XmlMembersMapping inHeaderMappings, XmlMembersMapping outHeaderMappings, SoapReflectedHeader[] headers, bool rpc) {
            // 
            if (use == SoapBindingUse.Encoded) {
                SoapExporter.ExportMembersMapping(inHeaderMappings, false);
                if (outHeaderMappings != null)
                    SoapExporter.ExportMembersMapping(outHeaderMappings, false);
            }
            else {
                SchemaExporter.ExportMembersMapping(inHeaderMappings);
                if (outHeaderMappings != null)
                    SchemaExporter.ExportMembersMapping(outHeaderMappings);
            }

            CodeIdentifiers identifiers = new CodeIdentifiers();
            int inCount = 0, outCount = 0;
            for (int i = 0; i < headers.Length; i++) {
                SoapReflectedHeader soapHeader = headers[i];
                if (!soapHeader.custom) continue;
                
                XmlMemberMapping member;
                if ((soapHeader.direction & SoapHeaderDirection.In) != 0) {
                    member = inHeaderMappings[inCount++];
                    if (soapHeader.direction != SoapHeaderDirection.In)
                        outCount++;
                }
                else {
                    member = outHeaderMappings[outCount++];
                }

                MessagePart part = new MessagePart();
                part.Name = member.XsdElementName;
                if (use == SoapBindingUse.Encoded)
                    part.Type = new XmlQualifiedName(member.TypeName, member.TypeNamespace);
                else
                    part.Element = new XmlQualifiedName(member.XsdElementName, member.Namespace);
                Message message = new Message();
                message.Name = identifiers.AddUnique(methodName + part.Name, message);
                message.Parts.Add(part);
                HeaderMessages.Add(message);

                ServiceDescriptionFormatExtension soapHeaderBinding = CreateSoapHeaderBinding(new XmlQualifiedName(message.Name, Binding.ServiceDescription.TargetNamespace), part.Name, rpc ? member.Namespace : null, use);
                
                if ((soapHeader.direction & SoapHeaderDirection.In) != 0)
                    OperationBinding.Input.Extensions.Add(soapHeaderBinding);
                if ((soapHeader.direction & SoapHeaderDirection.Out) != 0)
                    OperationBinding.Output.Extensions.Add(soapHeaderBinding);

                if ((soapHeader.direction & SoapHeaderDirection.Fault) != 0) {
                    if (soapMethod.IsClaimsConformance) {
                        throw new InvalidOperationException(Res.GetString(Res.BPConformanceHeaderFault, soapMethod.methodInfo.ToString(), soapMethod.methodInfo.DeclaringType.FullName, "Direction", typeof(SoapHeaderDirection).Name, SoapHeaderDirection.Fault.ToString())); 
                    }
                    OperationBinding.Output.Extensions.Add(soapHeaderBinding);
                }
            }
        }
示例#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);
            }
        }
        internal static SoapReflectedMethod ReflectMethod(LogicalMethodInfo methodInfo, bool client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, string defaultNs) {
            try {
                string methodId = methodInfo.GetKey();
                SoapReflectedMethod soapMethod = new SoapReflectedMethod();
                MethodAttribute methodAttribute = new MethodAttribute();

                object serviceAttr = GetSoapServiceAttribute(methodInfo.DeclaringType);
                bool serviceDefaultIsEncoded = ServiceDefaultIsEncoded(serviceAttr);
                object methodAttr = GetSoapMethodAttribute(methodInfo);
                if (methodAttr == null) {
                    if (client) return null; // method attribute required on the client
                    if (serviceAttr is SoapRpcServiceAttribute) {
                        SoapRpcMethodAttribute method = new SoapRpcMethodAttribute();
                        method.Use = ((SoapRpcServiceAttribute)serviceAttr).Use;
                        methodAttr = method;
                    }
                    else if (serviceAttr is SoapDocumentServiceAttribute) {
                        SoapDocumentMethodAttribute method = new SoapDocumentMethodAttribute();
                        method.Use = ((SoapDocumentServiceAttribute)serviceAttr).Use;
                        methodAttr = method;
                    }
                    else {
                        methodAttr = new SoapDocumentMethodAttribute();
                    }
                }

                if (methodAttr is SoapRpcMethodAttribute) {
                    SoapRpcMethodAttribute attr = (SoapRpcMethodAttribute)methodAttr;

                    soapMethod.rpc = true;
                    soapMethod.use = attr.Use;
                    soapMethod.oneWay = attr.OneWay;
                    methodAttribute.action = attr.Action;
                    methodAttribute.binding = attr.Binding;
                    methodAttribute.requestName = attr.RequestElementName;
                    methodAttribute.requestNs = attr.RequestNamespace;
                    methodAttribute.responseName = attr.ResponseElementName;
                    methodAttribute.responseNs = attr.ResponseNamespace;
                }
                else {
                    SoapDocumentMethodAttribute attr = (SoapDocumentMethodAttribute)methodAttr;
                    
                    soapMethod.rpc = false;
                    soapMethod.use = attr.Use;
                    soapMethod.paramStyle = attr.ParameterStyle;
                    soapMethod.oneWay = attr.OneWay;
                    methodAttribute.action = attr.Action;
                    methodAttribute.binding = attr.Binding;
                    methodAttribute.requestName = attr.RequestElementName;
                    methodAttribute.requestNs = attr.RequestNamespace;
                    methodAttribute.responseName = attr.ResponseElementName;
                    methodAttribute.responseNs = attr.ResponseNamespace;

                    if (soapMethod.use == SoapBindingUse.Default) {
                        if (serviceAttr is SoapDocumentServiceAttribute)
                            soapMethod.use = ((SoapDocumentServiceAttribute)serviceAttr).Use;
                        if (soapMethod.use == SoapBindingUse.Default)
                            soapMethod.use = SoapBindingUse.Literal;
                    }
                    if (soapMethod.paramStyle == SoapParameterStyle.Default) {
                        if (serviceAttr is SoapDocumentServiceAttribute)
                            soapMethod.paramStyle = ((SoapDocumentServiceAttribute)serviceAttr).ParameterStyle;
                        if (soapMethod.paramStyle == SoapParameterStyle.Default)
                            soapMethod.paramStyle = SoapParameterStyle.Wrapped;
                    }
                }

                if (methodAttribute.binding.Length > 0) {
                    if (client) throw new InvalidOperationException(Res.GetString(Res.WebInvalidBindingPlacement, methodAttr.GetType().Name));
                    soapMethod.binding = WebServiceBindingReflector.GetAttribute(methodInfo, methodAttribute.binding);
                }

                WebMethodAttribute webMethodAttribute = methodInfo.MethodAttribute;

                // 
                soapMethod.name = webMethodAttribute.MessageName;
                if (soapMethod.name.Length == 0) soapMethod.name = methodInfo.Name;

                string requestElementName;
                if (soapMethod.rpc) {
                    // in the case when we interop with non .net we might need to chnage the method name.
                    requestElementName = methodAttribute.requestName.Length == 0 || !client ? methodInfo.Name : methodAttribute.requestName;
                }
                else {
                    requestElementName = methodAttribute.requestName.Length == 0 ? soapMethod.name : methodAttribute.requestName;
                }
                string requestNamespace = methodAttribute.requestNs;

                if (requestNamespace == null) {
                    if (soapMethod.binding != null && soapMethod.binding.Namespace != null && soapMethod.binding.Namespace.Length != 0)
                        requestNamespace = soapMethod.binding.Namespace;
                    else
                        requestNamespace = defaultNs;
                }

                string responseElementName;
                if (soapMethod.rpc && soapMethod.use != SoapBindingUse.Encoded)
                {
                    // NOTE: this rule should apply equally to rpc/lit and rpc/enc, but to reduce risk, i'm only applying it to rpc/lit
                    responseElementName = methodInfo.Name + "Response";
                }
                else
                {
                    responseElementName = methodAttribute.responseName.Length == 0 ? soapMethod.name + "Response" : methodAttribute.responseName;
                }
                string responseNamespace = methodAttribute.responseNs;

                if (responseNamespace == null) {
                    if (soapMethod.binding != null && soapMethod.binding.Namespace != null && soapMethod.binding.Namespace.Length != 0)
                        responseNamespace = soapMethod.binding.Namespace;
                    else
                        responseNamespace = defaultNs;
                }

                SoapParameterInfo[] inParameters = ReflectParameters(methodInfo.InParameters, requestNamespace);
                SoapParameterInfo[] outParameters = ReflectParameters(methodInfo.OutParameters, responseNamespace);

                soapMethod.action = methodAttribute.action;
                if (soapMethod.action == null)
                    soapMethod.action = GetDefaultAction(defaultNs, methodInfo);
                soapMethod.methodInfo = methodInfo;

                if (soapMethod.oneWay) {
                    if (outParameters.Length > 0) throw new ArgumentException(Res.GetString(Res.WebOneWayOutParameters), "methodInfo");
                    if (methodInfo.ReturnType != typeof(void)) throw new ArgumentException(Res.GetString(Res.WebOneWayReturnValue), "methodInfo");
                }

                XmlReflectionMember[] members = new XmlReflectionMember[inParameters.Length];
                for (int i = 0; i < members.Length; i++) {
                    SoapParameterInfo soapParamInfo = inParameters[i];
                    XmlReflectionMember member = new XmlReflectionMember();
                    member.MemberName = soapParamInfo.parameterInfo.Name;
                    member.MemberType = soapParamInfo.parameterInfo.ParameterType;
                    if (member.MemberType.IsByRef)
                        member.MemberType = member.MemberType.GetElementType();
                    member.XmlAttributes = soapParamInfo.xmlAttributes;
                    member.SoapAttributes = soapParamInfo.soapAttributes;
                    members[i] = member;
                }
                soapMethod.requestMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, soapMethod.rpc, soapMethod.use, soapMethod.paramStyle, requestElementName, requestNamespace, methodAttribute.requestNs == null, members, true, false, methodId, client);

                if (GetSoapServiceRoutingStyle(serviceAttr) == SoapServiceRoutingStyle.RequestElement &&
                    soapMethod.paramStyle == SoapParameterStyle.Bare &&
                    soapMethod.requestMappings.Count != 1)
                    throw new ArgumentException(Res.GetString(Res.WhenUsingAMessageStyleOfParametersAsDocument0), "methodInfo");

                string elementName = "";
                string elementNamespace = "";
                if (soapMethod.paramStyle == SoapParameterStyle.Bare) {
                    if (soapMethod.requestMappings.Count == 1) {
                        elementName = soapMethod.requestMappings[0].XsdElementName;
                        elementNamespace = soapMethod.requestMappings[0].Namespace;
                    }
                    // else: can't route on request element -- we match on an empty qname, 
                    //       normal rules apply for duplicates
                }
                else {
                    elementName = soapMethod.requestMappings.XsdElementName;
                    elementNamespace = soapMethod.requestMappings.Namespace;
                }
                soapMethod.requestElementName = new XmlQualifiedName(elementName, elementNamespace);
                
                if (!soapMethod.oneWay) {
                    int numOutParams = outParameters.Length;
                    int count = 0;
                    CodeIdentifiers identifiers = null;
                    if (methodInfo.ReturnType != typeof(void)) {
                        numOutParams++;
                        count = 1;
                        identifiers = new CodeIdentifiers();
                    }
                    members = new XmlReflectionMember[numOutParams];

                    for (int i = 0; i < outParameters.Length; i++) {
                        SoapParameterInfo soapParamInfo = outParameters[i];
                        XmlReflectionMember member = new XmlReflectionMember();
                        member.MemberName = soapParamInfo.parameterInfo.Name;
                        member.MemberType = soapParamInfo.parameterInfo.ParameterType;
                        if (member.MemberType.IsByRef)
                            member.MemberType = member.MemberType.GetElementType();
                        member.XmlAttributes = soapParamInfo.xmlAttributes;
                        member.SoapAttributes = soapParamInfo.soapAttributes;
                        members[count++] = member;
                        if (identifiers != null)
                            identifiers.Add(member.MemberName, null);
                    }
                    if (methodInfo.ReturnType != typeof(void)) {
                        XmlReflectionMember member = new XmlReflectionMember();
                        member.MemberName = identifiers.MakeUnique(soapMethod.name + "Result");
                        member.MemberType = methodInfo.ReturnType;
                        member.IsReturnValue = true;

                        member.XmlAttributes = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider);
                        member.XmlAttributes.XmlRoot = null; // Ignore XmlRoot attribute used by get/post
                        member.SoapAttributes = new SoapAttributes(methodInfo.ReturnTypeCustomAttributeProvider);

                        members[0] = member;
                    }
                    soapMethod.responseMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, soapMethod.rpc, soapMethod.use, soapMethod.paramStyle, responseElementName, responseNamespace, methodAttribute.responseNs == null, members, false, false, methodId + ":Response", !client);

                }

                SoapExtensionAttribute[] extensionAttributes = (SoapExtensionAttribute[])methodInfo.GetCustomAttributes(typeof(SoapExtensionAttribute));
                soapMethod.extensions = new SoapReflectedExtension[extensionAttributes.Length];
                for (int i = 0; i < extensionAttributes.Length; i++)
                    soapMethod.extensions[i] = new SoapReflectedExtension(extensionAttributes[i].ExtensionType, extensionAttributes[i]);
                Array.Sort(soapMethod.extensions);

                SoapHeaderAttribute[] headerAttributes = (SoapHeaderAttribute[])methodInfo.GetCustomAttributes(typeof(SoapHeaderAttribute));
                Array.Sort(headerAttributes, new SoapHeaderAttributeComparer());
                Hashtable headerTypes = new Hashtable();
                soapMethod.headers = new SoapReflectedHeader[headerAttributes.Length];
                int front = 0;
                int back = soapMethod.headers.Length;
                ArrayList inHeaders = new ArrayList();
                ArrayList outHeaders = new ArrayList();
                for (int i = 0; i < soapMethod.headers.Length; i++) {
                    SoapHeaderAttribute headerAttribute = headerAttributes[i];
                    SoapReflectedHeader soapHeader = new SoapReflectedHeader();
                    Type declaringType = methodInfo.DeclaringType;
                    if ((soapHeader.memberInfo = declaringType.GetField(headerAttribute.MemberName)) != null) {
                        soapHeader.headerType = ((FieldInfo)soapHeader.memberInfo).FieldType;
                    }
                    else if ((soapHeader.memberInfo = declaringType.GetProperty(headerAttribute.MemberName)) != null) {
                        soapHeader.headerType = ((PropertyInfo)soapHeader.memberInfo).PropertyType;
                    }
                    else {
                        throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderMissing);
                    }
                    if (soapHeader.headerType.IsArray) {
                        soapHeader.headerType = soapHeader.headerType.GetElementType();
                        soapHeader.repeats = true;
                        if (soapHeader.headerType != typeof(SoapUnknownHeader) && soapHeader.headerType != typeof(SoapHeader))
                            throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderType);
                    }
                    if (MemberHelper.IsStatic(soapHeader.memberInfo)) throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderStatic);
                    if (!MemberHelper.CanRead(soapHeader.memberInfo)) throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderRead);
                    if (!MemberHelper.CanWrite(soapHeader.memberInfo)) throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderWrite);
                    if (!typeof(SoapHeader).IsAssignableFrom(soapHeader.headerType)) throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderType);
                    
                    SoapHeaderDirection direction = headerAttribute.Direction;
                    if (soapMethod.oneWay && (direction & (SoapHeaderDirection.Out | SoapHeaderDirection.Fault)) != 0) throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderOneWayOut);
                    if (headerTypes.Contains(soapHeader.headerType)) {
                        SoapHeaderDirection prevDirection = (SoapHeaderDirection) headerTypes[soapHeader.headerType];
                        if ((prevDirection & direction) != 0)
                            throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebMultiplyDeclaredHeaderTypes);
                        headerTypes[soapHeader.headerType] = direction | prevDirection;
                    }
                    else
                        headerTypes[soapHeader.headerType] = direction;
                    
                    if (soapHeader.headerType != typeof(SoapHeader) && soapHeader.headerType != typeof(SoapUnknownHeader)) {
                        XmlReflectionMember member = new XmlReflectionMember();
                        member.MemberName = soapHeader.headerType.Name;
                        member.MemberType = soapHeader.headerType;

                        XmlAttributes a = new XmlAttributes(soapHeader.headerType);
                        if (a.XmlRoot != null) {
                            member.XmlAttributes = new XmlAttributes();
                            XmlElementAttribute attr = new XmlElementAttribute();
                            attr.ElementName = a.XmlRoot.ElementName;
                            attr.Namespace = a.XmlRoot.Namespace;
                            member.XmlAttributes.XmlElements.Add(attr);
                        }
                        member.OverrideIsNullable = true;
                        
                        if ((direction & SoapHeaderDirection.In) != 0)
                            inHeaders.Add(member);
                        if ((direction & (SoapHeaderDirection.Out | SoapHeaderDirection.Fault)) != 0)
                            outHeaders.Add(member);

                        soapHeader.custom = true;
                    }
                    soapHeader.direction = direction;
                    // Put generic header mappings at the end of the list so they are found last during header processing
                    if (!soapHeader.custom) {
                        soapMethod.headers[--back] = soapHeader;
                    }
                    else {
                        soapMethod.headers[front++] = soapHeader;
                    }
                }
                soapMethod.inHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, soapMethod.use, SoapParameterStyle.Bare, requestElementName + "InHeaders", defaultNs, true, (XmlReflectionMember[]) inHeaders.ToArray(typeof(XmlReflectionMember)), false, true, methodId + ":InHeaders", client);
                if (!soapMethod.oneWay)
                    soapMethod.outHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, soapMethod.use, SoapParameterStyle.Bare, responseElementName + "OutHeaders", defaultNs, true, (XmlReflectionMember[]) outHeaders.ToArray(typeof(XmlReflectionMember)), false, true, methodId + ":OutHeaders", !client);
                
                return soapMethod;
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }
                throw new InvalidOperationException(Res.GetString(Res.WebReflectionErrorMethod, methodInfo.DeclaringType.Name, methodInfo.Name), e);
            }
        }
        internal static SoapReflectedMethod ReflectMethod(LogicalMethodInfo methodInfo, bool client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, string defaultNs)
        {
            SoapReflectedMethod method2;

            try
            {
                string str2;
                string str4;
                string key = methodInfo.GetKey();
                SoapReflectedMethod method     = new SoapReflectedMethod();
                MethodAttribute     attribute  = new MethodAttribute();
                object soapServiceAttribute    = GetSoapServiceAttribute(methodInfo.DeclaringType);
                bool   serviceDefaultIsEncoded = ServiceDefaultIsEncoded(soapServiceAttribute);
                object soapMethodAttribute     = GetSoapMethodAttribute(methodInfo);
                if (soapMethodAttribute == null)
                {
                    if (client)
                    {
                        return(null);
                    }
                    if (soapServiceAttribute is SoapRpcServiceAttribute)
                    {
                        SoapRpcMethodAttribute attribute2 = new SoapRpcMethodAttribute {
                            Use = ((SoapRpcServiceAttribute)soapServiceAttribute).Use
                        };
                        soapMethodAttribute = attribute2;
                    }
                    else if (soapServiceAttribute is SoapDocumentServiceAttribute)
                    {
                        SoapDocumentMethodAttribute attribute3 = new SoapDocumentMethodAttribute {
                            Use = ((SoapDocumentServiceAttribute)soapServiceAttribute).Use
                        };
                        soapMethodAttribute = attribute3;
                    }
                    else
                    {
                        soapMethodAttribute = new SoapDocumentMethodAttribute();
                    }
                }
                if (soapMethodAttribute is SoapRpcMethodAttribute)
                {
                    SoapRpcMethodAttribute attribute4 = (SoapRpcMethodAttribute)soapMethodAttribute;
                    method.rpc             = true;
                    method.use             = attribute4.Use;
                    method.oneWay          = attribute4.OneWay;
                    attribute.action       = attribute4.Action;
                    attribute.binding      = attribute4.Binding;
                    attribute.requestName  = attribute4.RequestElementName;
                    attribute.requestNs    = attribute4.RequestNamespace;
                    attribute.responseName = attribute4.ResponseElementName;
                    attribute.responseNs   = attribute4.ResponseNamespace;
                }
                else
                {
                    SoapDocumentMethodAttribute attribute5 = (SoapDocumentMethodAttribute)soapMethodAttribute;
                    method.rpc             = false;
                    method.use             = attribute5.Use;
                    method.paramStyle      = attribute5.ParameterStyle;
                    method.oneWay          = attribute5.OneWay;
                    attribute.action       = attribute5.Action;
                    attribute.binding      = attribute5.Binding;
                    attribute.requestName  = attribute5.RequestElementName;
                    attribute.requestNs    = attribute5.RequestNamespace;
                    attribute.responseName = attribute5.ResponseElementName;
                    attribute.responseNs   = attribute5.ResponseNamespace;
                    if (method.use == SoapBindingUse.Default)
                    {
                        if (soapServiceAttribute is SoapDocumentServiceAttribute)
                        {
                            method.use = ((SoapDocumentServiceAttribute)soapServiceAttribute).Use;
                        }
                        if (method.use == SoapBindingUse.Default)
                        {
                            method.use = SoapBindingUse.Literal;
                        }
                    }
                    if (method.paramStyle == SoapParameterStyle.Default)
                    {
                        if (soapServiceAttribute is SoapDocumentServiceAttribute)
                        {
                            method.paramStyle = ((SoapDocumentServiceAttribute)soapServiceAttribute).ParameterStyle;
                        }
                        if (method.paramStyle == SoapParameterStyle.Default)
                        {
                            method.paramStyle = SoapParameterStyle.Wrapped;
                        }
                    }
                }
                if (attribute.binding.Length > 0)
                {
                    if (client)
                    {
                        throw new InvalidOperationException(System.Web.Services.Res.GetString("WebInvalidBindingPlacement", new object[] { soapMethodAttribute.GetType().Name }));
                    }
                    method.binding = WebServiceBindingReflector.GetAttribute(methodInfo, attribute.binding);
                }
                WebMethodAttribute methodAttribute = methodInfo.MethodAttribute;
                method.name = methodAttribute.MessageName;
                if (method.name.Length == 0)
                {
                    method.name = methodInfo.Name;
                }
                if (method.rpc)
                {
                    str2 = ((attribute.requestName.Length == 0) || !client) ? methodInfo.Name : attribute.requestName;
                }
                else
                {
                    str2 = (attribute.requestName.Length == 0) ? method.name : attribute.requestName;
                }
                string requestNs = attribute.requestNs;
                if (requestNs == null)
                {
                    if (((method.binding != null) && (method.binding.Namespace != null)) && (method.binding.Namespace.Length != 0))
                    {
                        requestNs = method.binding.Namespace;
                    }
                    else
                    {
                        requestNs = defaultNs;
                    }
                }
                if (method.rpc && (method.use != SoapBindingUse.Encoded))
                {
                    str4 = methodInfo.Name + "Response";
                }
                else
                {
                    str4 = (attribute.responseName.Length == 0) ? (method.name + "Response") : attribute.responseName;
                }
                string responseNs = attribute.responseNs;
                if (responseNs == null)
                {
                    if (((method.binding != null) && (method.binding.Namespace != null)) && (method.binding.Namespace.Length != 0))
                    {
                        responseNs = method.binding.Namespace;
                    }
                    else
                    {
                        responseNs = defaultNs;
                    }
                }
                SoapParameterInfo[] infoArray  = ReflectParameters(methodInfo.InParameters, requestNs);
                SoapParameterInfo[] infoArray2 = ReflectParameters(methodInfo.OutParameters, responseNs);
                method.action = attribute.action;
                if (method.action == null)
                {
                    method.action = GetDefaultAction(defaultNs, methodInfo);
                }
                method.methodInfo = methodInfo;
                if (method.oneWay)
                {
                    if (infoArray2.Length > 0)
                    {
                        throw new ArgumentException(System.Web.Services.Res.GetString("WebOneWayOutParameters"), "methodInfo");
                    }
                    if (methodInfo.ReturnType != typeof(void))
                    {
                        throw new ArgumentException(System.Web.Services.Res.GetString("WebOneWayReturnValue"), "methodInfo");
                    }
                }
                XmlReflectionMember[] members = new XmlReflectionMember[infoArray.Length];
                for (int i = 0; i < members.Length; i++)
                {
                    SoapParameterInfo   info   = infoArray[i];
                    XmlReflectionMember member = new XmlReflectionMember {
                        MemberName = info.parameterInfo.Name,
                        MemberType = info.parameterInfo.ParameterType
                    };
                    if (member.MemberType.IsByRef)
                    {
                        member.MemberType = member.MemberType.GetElementType();
                    }
                    member.XmlAttributes  = info.xmlAttributes;
                    member.SoapAttributes = info.soapAttributes;
                    members[i]            = member;
                }
                method.requestMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, method.rpc, method.use, method.paramStyle, str2, requestNs, attribute.requestNs == null, members, true, false, key, client);
                if (((GetSoapServiceRoutingStyle(soapServiceAttribute) == SoapServiceRoutingStyle.RequestElement) && (method.paramStyle == SoapParameterStyle.Bare)) && (method.requestMappings.Count != 1))
                {
                    throw new ArgumentException(System.Web.Services.Res.GetString("WhenUsingAMessageStyleOfParametersAsDocument0"), "methodInfo");
                }
                string name = "";
                string ns   = "";
                if (method.paramStyle == SoapParameterStyle.Bare)
                {
                    if (method.requestMappings.Count == 1)
                    {
                        name = method.requestMappings[0].XsdElementName;
                        ns   = method.requestMappings[0].Namespace;
                    }
                }
                else
                {
                    name = method.requestMappings.XsdElementName;
                    ns   = method.requestMappings.Namespace;
                }
                method.requestElementName = new XmlQualifiedName(name, ns);
                if (!method.oneWay)
                {
                    int             num2        = infoArray2.Length;
                    int             num3        = 0;
                    CodeIdentifiers identifiers = null;
                    if (methodInfo.ReturnType != typeof(void))
                    {
                        num2++;
                        num3        = 1;
                        identifiers = new CodeIdentifiers();
                    }
                    members = new XmlReflectionMember[num2];
                    for (int m = 0; m < infoArray2.Length; m++)
                    {
                        SoapParameterInfo   info2   = infoArray2[m];
                        XmlReflectionMember member2 = new XmlReflectionMember {
                            MemberName = info2.parameterInfo.Name,
                            MemberType = info2.parameterInfo.ParameterType
                        };
                        if (member2.MemberType.IsByRef)
                        {
                            member2.MemberType = member2.MemberType.GetElementType();
                        }
                        member2.XmlAttributes  = info2.xmlAttributes;
                        member2.SoapAttributes = info2.soapAttributes;
                        members[num3++]        = member2;
                        if (identifiers != null)
                        {
                            identifiers.Add(member2.MemberName, null);
                        }
                    }
                    if (methodInfo.ReturnType != typeof(void))
                    {
                        XmlReflectionMember member3 = new XmlReflectionMember {
                            MemberName    = identifiers.MakeUnique(method.name + "Result"),
                            MemberType    = methodInfo.ReturnType,
                            IsReturnValue = true,
                            XmlAttributes = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider)
                        };
                        member3.XmlAttributes.XmlRoot = null;
                        member3.SoapAttributes        = new SoapAttributes(methodInfo.ReturnTypeCustomAttributeProvider);
                        members[0] = member3;
                    }
                    method.responseMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, method.rpc, method.use, method.paramStyle, str4, responseNs, attribute.responseNs == null, members, false, false, key + ":Response", !client);
                }
                SoapExtensionAttribute[] customAttributes = (SoapExtensionAttribute[])methodInfo.GetCustomAttributes(typeof(SoapExtensionAttribute));
                method.extensions = new SoapReflectedExtension[customAttributes.Length];
                for (int j = 0; j < customAttributes.Length; j++)
                {
                    method.extensions[j] = new SoapReflectedExtension(customAttributes[j].ExtensionType, customAttributes[j]);
                }
                Array.Sort <SoapReflectedExtension>(method.extensions);
                SoapHeaderAttribute[] array = (SoapHeaderAttribute[])methodInfo.GetCustomAttributes(typeof(SoapHeaderAttribute));
                Array.Sort(array, new SoapHeaderAttributeComparer());
                Hashtable hashtable = new Hashtable();
                method.headers = new SoapReflectedHeader[array.Length];
                int       num6   = 0;
                int       length = method.headers.Length;
                ArrayList list   = new ArrayList();
                ArrayList list2  = new ArrayList();
                for (int k = 0; k < method.headers.Length; k++)
                {
                    SoapHeaderAttribute attribute7 = array[k];
                    SoapReflectedHeader header     = new SoapReflectedHeader();
                    Type declaringType             = methodInfo.DeclaringType;
                    header.memberInfo = declaringType.GetField(attribute7.MemberName);
                    if (header.memberInfo != null)
                    {
                        header.headerType = ((FieldInfo)header.memberInfo).FieldType;
                    }
                    else
                    {
                        header.memberInfo = declaringType.GetProperty(attribute7.MemberName);
                        if (header.memberInfo == null)
                        {
                            throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderMissing");
                        }
                        header.headerType = ((PropertyInfo)header.memberInfo).PropertyType;
                    }
                    if (header.headerType.IsArray)
                    {
                        header.headerType = header.headerType.GetElementType();
                        header.repeats    = true;
                        if ((header.headerType != typeof(SoapUnknownHeader)) && (header.headerType != typeof(SoapHeader)))
                        {
                            throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderType");
                        }
                    }
                    if (MemberHelper.IsStatic(header.memberInfo))
                    {
                        throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderStatic");
                    }
                    if (!MemberHelper.CanRead(header.memberInfo))
                    {
                        throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderRead");
                    }
                    if (!MemberHelper.CanWrite(header.memberInfo))
                    {
                        throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderWrite");
                    }
                    if (!typeof(SoapHeader).IsAssignableFrom(header.headerType))
                    {
                        throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderType");
                    }
                    SoapHeaderDirection direction = attribute7.Direction;
                    if (method.oneWay && ((direction & (SoapHeaderDirection.Fault | SoapHeaderDirection.Out)) != 0))
                    {
                        throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderOneWayOut");
                    }
                    if (hashtable.Contains(header.headerType))
                    {
                        SoapHeaderDirection direction2 = (SoapHeaderDirection)hashtable[header.headerType];
                        if ((direction2 & direction) != 0)
                        {
                            throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebMultiplyDeclaredHeaderTypes");
                        }
                        hashtable[header.headerType] = direction | direction2;
                    }
                    else
                    {
                        hashtable[header.headerType] = direction;
                    }
                    if ((header.headerType != typeof(SoapHeader)) && (header.headerType != typeof(SoapUnknownHeader)))
                    {
                        XmlReflectionMember member4 = new XmlReflectionMember {
                            MemberName = header.headerType.Name,
                            MemberType = header.headerType
                        };
                        XmlAttributes attributes = new XmlAttributes(header.headerType);
                        if (attributes.XmlRoot != null)
                        {
                            member4.XmlAttributes = new XmlAttributes();
                            XmlElementAttribute attribute8 = new XmlElementAttribute {
                                ElementName = attributes.XmlRoot.ElementName,
                                Namespace   = attributes.XmlRoot.Namespace
                            };
                            member4.XmlAttributes.XmlElements.Add(attribute8);
                        }
                        member4.OverrideIsNullable = true;
                        if ((direction & SoapHeaderDirection.In) != 0)
                        {
                            list.Add(member4);
                        }
                        if ((direction & (SoapHeaderDirection.Fault | SoapHeaderDirection.Out)) != 0)
                        {
                            list2.Add(member4);
                        }
                        header.custom = true;
                    }
                    header.direction = direction;
                    if (!header.custom)
                    {
                        method.headers[--length] = header;
                    }
                    else
                    {
                        method.headers[num6++] = header;
                    }
                }
                method.inHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, method.use, SoapParameterStyle.Bare, str2 + "InHeaders", defaultNs, true, (XmlReflectionMember[])list.ToArray(typeof(XmlReflectionMember)), false, true, key + ":InHeaders", client);
                if (!method.oneWay)
                {
                    method.outHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, method.use, SoapParameterStyle.Bare, str4 + "OutHeaders", defaultNs, true, (XmlReflectionMember[])list2.ToArray(typeof(XmlReflectionMember)), false, true, key + ":OutHeaders", !client);
                }
                method2 = method;
            }
            catch (Exception exception)
            {
                if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                {
                    throw;
                }
                throw new InvalidOperationException(System.Web.Services.Res.GetString("WebReflectionErrorMethod", new object[] { methodInfo.DeclaringType.Name, methodInfo.Name }), exception);
            }
            return(method2);
        }
        internal SoapClientType(Type type)
        {
            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);
            ArrayList soapMethodList = new ArrayList();
            ArrayList mappings       = new ArrayList();

            GenerateXmlMappings(type, soapMethodList, serviceNamespace, serviceDefaultIsEncoded, mappings);
            XmlMapping[] xmlMappings = (XmlMapping[])mappings.ToArray(typeof(XmlMapping));

            TraceMethod caller = Tracing.On ? new TraceMethod(this, ".ctor", type) : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId(Res.TraceCreateSerializer), caller, new TraceMethod(typeof(XmlSerializer), "FromMappings", xmlMappings, type));
            }
            XmlSerializer[] serializers = XmlSerializer.FromMappings(xmlMappings, type);
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId(Res.TraceCreateSerializer), caller);
            }

            SoapExtensionTypeElementCollection extensionTypes = WebServicesSection.Current.SoapExtensionTypes;
            ArrayList highPri = new ArrayList();
            ArrayList lowPri  = new ArrayList();

            for (int i = 0; i < extensionTypes.Count; i++)
            {
                SoapExtensionTypeElement element   = extensionTypes[i];
                SoapReflectedExtension   extension = new SoapReflectedExtension(extensionTypes[i].Type, null, extensionTypes[i].Priority);
                if (extensionTypes[i].Group == 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);

            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);
            }
        }
示例#8
0
        internal SoapServerType(Type type, ProtocolsEnum versionsSupported) : base(type)
        {
            this.versionsSupported = versionsSupported;
            bool soap11 = (versionsSupported & ProtocolsEnum.HttpSoap) != 0;
            bool soap12 = (versionsSupported & ProtocolsEnum.HttpSoap12) != 0;

            LogicalMethodInfo[] methodInfos      = WebMethodReflector.GetMethods(type);
            ArrayList           mappings         = new ArrayList();
            WebServiceAttribute serviceAttribute = WebServiceReflector.GetAttribute(type);
            object soapServiceAttribute          = SoapReflector.GetSoapServiceAttribute(type);

            routingOnSoapAction     = SoapReflector.GetSoapServiceRoutingStyle(soapServiceAttribute) == SoapServiceRoutingStyle.SoapAction;
            serviceNamespace        = serviceAttribute.Namespace;
            serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(type);
            SoapReflectionImporter soapImporter = SoapReflector.CreateSoapImporter(serviceNamespace, serviceDefaultIsEncoded);
            XmlReflectionImporter  xmlImporter  = SoapReflector.CreateXmlImporter(serviceNamespace, serviceDefaultIsEncoded);

            SoapReflector.IncludeTypes(methodInfos, soapImporter);
            WebMethodReflector.IncludeTypes(methodInfos, xmlImporter);
            SoapReflectedMethod[] soapMethods = new SoapReflectedMethod[methodInfos.Length];

            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, false, xmlImporter, soapImporter, serviceAttribute.Namespace);
                mappings.Add(soapMethod.requestMappings);
                if (soapMethod.responseMappings != null)
                {
                    mappings.Add(soapMethod.responseMappings);
                }
                mappings.Add(soapMethod.inHeaderMappings);
                if (soapMethod.outHeaderMappings != null)
                {
                    mappings.Add(soapMethod.outHeaderMappings);
                }
                soapMethods[i] = soapMethod;
            }

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

            for (int i = 0; i < soapMethods.Length; i++)
            {
                SoapServerMethod    serverMethod = new SoapServerMethod();
                SoapReflectedMethod soapMethod   = soapMethods[i];
                serverMethod.parameterSerializer = serializers[count++];
                if (soapMethod.responseMappings != null)
                {
                    serverMethod.returnSerializer = serializers[count++];
                }
                serverMethod.inHeaderSerializer = serializers[count++];
                if (soapMethod.outHeaderMappings != null)
                {
                    serverMethod.outHeaderSerializer = serializers[count++];
                }
                serverMethod.methodInfo            = soapMethod.methodInfo;
                serverMethod.action                = soapMethod.action;
                serverMethod.extensions            = soapMethod.extensions;
                serverMethod.extensionInitializers = SoapReflectedExtension.GetInitializers(serverMethod.methodInfo, soapMethod.extensions);
                serverMethod.oneWay                = soapMethod.oneWay;
                serverMethod.rpc        = soapMethod.rpc;
                serverMethod.use        = soapMethod.use;
                serverMethod.paramStyle = soapMethod.paramStyle;
                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)
                    {
                        inHeaders.Add(mapping);
                    }
                    else if (mapping.direction == SoapHeaderDirection.Out)
                    {
                        outHeaders.Add(mapping);
                    }
                    else
                    {
                        inHeaders.Add(mapping);
                        outHeaders.Add(mapping);
                    }
                }
                serverMethod.inHeaderMappings = (SoapHeaderMapping[])inHeaders.ToArray(typeof(SoapHeaderMapping));
                if (serverMethod.outHeaderSerializer != null)
                {
                    serverMethod.outHeaderMappings = (SoapHeaderMapping[])outHeaders.ToArray(typeof(SoapHeaderMapping));
                }

                // check feasibility of routing on request element for soap 1.1
                if (soap11 && !routingOnSoapAction && soapMethod.requestElementName.IsEmpty)
                {
                    throw new SoapException(Res.GetString(Res.TheMethodDoesNotHaveARequestElementEither1, serverMethod.methodInfo.Name), new XmlQualifiedName(Soap.ClientCode, Soap.Namespace));
                }

                // we can lookup methods by action or request element
                if (methods[soapMethod.action] == null)
                {
                    methods[soapMethod.action] = serverMethod;
                }
                else
                {
                    // duplicate soap actions not allowed in soap 1.1 if we're routing on soap action
                    if (soap11 && routingOnSoapAction)
                    {
                        SoapServerMethod duplicateMethod = (SoapServerMethod)methods[soapMethod.action];
                        throw new SoapException(Res.GetString(Res.TheMethodsAndUseTheSameSoapActionWhenTheService3, serverMethod.methodInfo.Name, duplicateMethod.methodInfo.Name, soapMethod.action), new XmlQualifiedName(Soap.ClientCode, Soap.Namespace));
                    }
                    duplicateMethods[soapMethod.action] = serverMethod;
                }

                if (methods[soapMethod.requestElementName] == null)
                {
                    methods[soapMethod.requestElementName] = serverMethod;
                }
                else
                {
                    // duplicate request elements not allowed in soap 1.1 if we're routing on request element
                    if (soap11 && !routingOnSoapAction)
                    {
                        SoapServerMethod duplicateMethod = (SoapServerMethod)methods[soapMethod.requestElementName];
                        throw new SoapException(Res.GetString(Res.TheMethodsAndUseTheSameRequestElementXmlns4, serverMethod.methodInfo.Name, duplicateMethod.methodInfo.Name, soapMethod.requestElementName.Name, soapMethod.requestElementName.Namespace), new XmlQualifiedName(Soap.ClientCode, Soap.Namespace));
                    }
                    duplicateMethods[soapMethod.requestElementName] = serverMethod;
                }
            }
        }
示例#9
0
        internal SoapClientType(Type type)
        {
            this.binding = WebServiceBindingReflector.GetAttribute(type);
            if (this.binding == null)
            {
                throw new InvalidOperationException(Res.GetString("WebClientBindingAttributeRequired"));
            }
            this.serviceNamespace        = this.binding.Namespace;
            this.serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(type);
            ArrayList soapMethodList = new ArrayList();
            ArrayList mappings       = new ArrayList();

            GenerateXmlMappings(type, soapMethodList, this.serviceNamespace, this.serviceDefaultIsEncoded, mappings);
            XmlMapping[] mappingArray = (XmlMapping[])mappings.ToArray(typeof(XmlMapping));
            TraceMethod  caller       = Tracing.On ? new TraceMethod(this, ".ctor", new object[] { type }) : null;

            if (Tracing.On)
            {
                Tracing.Enter(Tracing.TraceId("TraceCreateSerializer"), caller, new TraceMethod(typeof(XmlSerializer), "FromMappings", new object[] { mappingArray, type }));
            }
            XmlSerializer[] serializerArray = XmlSerializer.FromMappings(mappingArray, type);
            if (Tracing.On)
            {
                Tracing.Exit(Tracing.TraceId("TraceCreateSerializer"), caller);
            }
            SoapExtensionTypeElementCollection soapExtensionTypes = WebServicesSection.Current.SoapExtensionTypes;
            ArrayList list3 = new ArrayList();
            ArrayList list4 = new ArrayList();

            for (int i = 0; i < soapExtensionTypes.Count; i++)
            {
                SoapExtensionTypeElement element1  = soapExtensionTypes[i];
                SoapReflectedExtension   extension = new SoapReflectedExtension(soapExtensionTypes[i].Type, null, soapExtensionTypes[i].Priority);
                if (soapExtensionTypes[i].Group == PriorityGroup.High)
                {
                    list3.Add(extension);
                }
                else
                {
                    list4.Add(extension);
                }
            }
            this.HighPriExtensions = (SoapReflectedExtension[])list3.ToArray(typeof(SoapReflectedExtension));
            this.LowPriExtensions  = (SoapReflectedExtension[])list4.ToArray(typeof(SoapReflectedExtension));
            Array.Sort <SoapReflectedExtension>(this.HighPriExtensions);
            Array.Sort <SoapReflectedExtension>(this.LowPriExtensions);
            this.HighPriExtensionInitializers = SoapReflectedExtension.GetInitializers(type, this.HighPriExtensions);
            this.LowPriExtensionInitializers  = SoapReflectedExtension.GetInitializers(type, this.LowPriExtensions);
            int num2 = 0;

            for (int j = 0; j < soapMethodList.Count; j++)
            {
                SoapReflectedMethod method2 = (SoapReflectedMethod)soapMethodList[j];
                SoapClientMethod    method3 = new SoapClientMethod {
                    parameterSerializer = serializerArray[num2++]
                };
                if (method2.responseMappings != null)
                {
                    method3.returnSerializer = serializerArray[num2++];
                }
                method3.inHeaderSerializer = serializerArray[num2++];
                if (method2.outHeaderMappings != null)
                {
                    method3.outHeaderSerializer = serializerArray[num2++];
                }
                method3.action                = method2.action;
                method3.oneWay                = method2.oneWay;
                method3.rpc                   = method2.rpc;
                method3.use                   = method2.use;
                method3.paramStyle            = method2.paramStyle;
                method3.methodInfo            = method2.methodInfo;
                method3.extensions            = method2.extensions;
                method3.extensionInitializers = SoapReflectedExtension.GetInitializers(method3.methodInfo, method2.extensions);
                ArrayList list5 = new ArrayList();
                ArrayList list6 = new ArrayList();
                for (int k = 0; k < method2.headers.Length; k++)
                {
                    SoapHeaderMapping   mapping = new SoapHeaderMapping();
                    SoapReflectedHeader header  = method2.headers[k];
                    mapping.memberInfo = header.memberInfo;
                    mapping.repeats    = header.repeats;
                    mapping.custom     = header.custom;
                    mapping.direction  = header.direction;
                    mapping.headerType = header.headerType;
                    if ((mapping.direction & SoapHeaderDirection.In) != 0)
                    {
                        list5.Add(mapping);
                    }
                    if ((mapping.direction & (SoapHeaderDirection.Fault | SoapHeaderDirection.Out)) != 0)
                    {
                        list6.Add(mapping);
                    }
                }
                method3.inHeaderMappings = (SoapHeaderMapping[])list5.ToArray(typeof(SoapHeaderMapping));
                if (method3.outHeaderSerializer != null)
                {
                    method3.outHeaderMappings = (SoapHeaderMapping[])list6.ToArray(typeof(SoapHeaderMapping));
                }
                this.methods.Add(method2.name, method3);
            }
        }
 private void CreateHeaderMessages(string methodName, SoapBindingUse use, XmlMembersMapping inHeaderMappings, XmlMembersMapping outHeaderMappings, SoapReflectedHeader[] headers, bool rpc)
 {
     if (use == SoapBindingUse.Encoded)
     {
         this.SoapExporter.ExportMembersMapping(inHeaderMappings, false);
         if (outHeaderMappings != null)
         {
             this.SoapExporter.ExportMembersMapping(outHeaderMappings, false);
         }
     }
     else
     {
         base.SchemaExporter.ExportMembersMapping(inHeaderMappings);
         if (outHeaderMappings != null)
         {
             base.SchemaExporter.ExportMembersMapping(outHeaderMappings);
         }
     }
     CodeIdentifiers identifiers = new CodeIdentifiers();
     int num = 0;
     int num2 = 0;
     for (int i = 0; i < headers.Length; i++)
     {
         SoapReflectedHeader header = headers[i];
         if (header.custom)
         {
             XmlMemberMapping mapping;
             Message message;
             if ((header.direction & SoapHeaderDirection.In) != 0)
             {
                 mapping = inHeaderMappings[num++];
                 if (header.direction != SoapHeaderDirection.In)
                 {
                     num2++;
                 }
             }
             else
             {
                 mapping = outHeaderMappings[num2++];
             }
             MessagePart messagePart = new MessagePart {
                 Name = mapping.XsdElementName
             };
             if (use == SoapBindingUse.Encoded)
             {
                 messagePart.Type = new XmlQualifiedName(mapping.TypeName, mapping.TypeNamespace);
             }
             else
             {
                 messagePart.Element = new XmlQualifiedName(mapping.XsdElementName, mapping.Namespace);
             }
             message = new Message {
                 Name = identifiers.AddUnique(methodName + messagePart.Name, message)
             };
             message.Parts.Add(messagePart);
             base.HeaderMessages.Add(message);
             ServiceDescriptionFormatExtension extension = this.CreateSoapHeaderBinding(new XmlQualifiedName(message.Name, base.Binding.ServiceDescription.TargetNamespace), messagePart.Name, rpc ? mapping.Namespace : null, use);
             if ((header.direction & SoapHeaderDirection.In) != 0)
             {
                 base.OperationBinding.Input.Extensions.Add(extension);
             }
             if ((header.direction & SoapHeaderDirection.Out) != 0)
             {
                 base.OperationBinding.Output.Extensions.Add(extension);
             }
             if ((header.direction & SoapHeaderDirection.Fault) != 0)
             {
                 if (this.soapMethod.IsClaimsConformance)
                 {
                     throw new InvalidOperationException(System.Web.Services.Res.GetString("BPConformanceHeaderFault", new object[] { this.soapMethod.methodInfo.ToString(), this.soapMethod.methodInfo.DeclaringType.FullName, "Direction", typeof(SoapHeaderDirection).Name, SoapHeaderDirection.Fault.ToString() }));
                 }
                 base.OperationBinding.Output.Extensions.Add(extension);
             }
         }
     }
 }
示例#11
0
        internal static SoapReflectedMethod ReflectMethod(LogicalMethodInfo methodInfo, bool client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, string defaultNs)
        {
            try {
                SoapReflectedMethod soapMethod      = new SoapReflectedMethod();
                MethodAttribute     methodAttribute = new MethodAttribute();

                object serviceAttr             = GetSoapServiceAttribute(methodInfo.DeclaringType);
                bool   serviceDefaultIsEncoded = ServiceDefaultIsEncoded(serviceAttr);
                object methodAttr = GetSoapMethodAttribute(methodInfo);
                if (methodAttr == null)
                {
                    if (client)
                    {
                        return(null);        // method attribute required on the client
                    }
                    if (serviceAttr is SoapRpcServiceAttribute)
                    {
                        methodAttr = new SoapRpcMethodAttribute();
                    }
                    else
                    {
                        methodAttr = new SoapDocumentMethodAttribute();
                    }
                }

                if (methodAttr is SoapRpcMethodAttribute)
                {
                    SoapRpcMethodAttribute attr = (SoapRpcMethodAttribute)methodAttr;

                    soapMethod.rpc               = true;
                    soapMethod.use               = SoapBindingUse.Encoded;
                    soapMethod.oneWay            = attr.OneWay;
                    methodAttribute.action       = attr.Action;
                    methodAttribute.binding      = attr.Binding;
                    methodAttribute.requestName  = attr.RequestElementName;
                    methodAttribute.requestNs    = attr.RequestNamespace;
                    methodAttribute.responseName = attr.ResponseElementName;
                    methodAttribute.responseNs   = attr.ResponseNamespace;
                }
                else
                {
                    SoapDocumentMethodAttribute attr = (SoapDocumentMethodAttribute)methodAttr;

                    soapMethod.rpc               = false;
                    soapMethod.use               = attr.Use;
                    soapMethod.paramStyle        = attr.ParameterStyle;
                    soapMethod.oneWay            = attr.OneWay;
                    methodAttribute.action       = attr.Action;
                    methodAttribute.binding      = attr.Binding;
                    methodAttribute.requestName  = attr.RequestElementName;
                    methodAttribute.requestNs    = attr.RequestNamespace;
                    methodAttribute.responseName = attr.ResponseElementName;
                    methodAttribute.responseNs   = attr.ResponseNamespace;

                    if (soapMethod.use == SoapBindingUse.Default)
                    {
                        if (serviceAttr is SoapDocumentServiceAttribute)
                        {
                            soapMethod.use = ((SoapDocumentServiceAttribute)serviceAttr).Use;
                        }
                        if (soapMethod.use == SoapBindingUse.Default)
                        {
                            soapMethod.use = SoapBindingUse.Literal;
                        }
                    }
                    if (soapMethod.paramStyle == SoapParameterStyle.Default)
                    {
                        if (serviceAttr is SoapDocumentServiceAttribute)
                        {
                            soapMethod.paramStyle = ((SoapDocumentServiceAttribute)serviceAttr).ParameterStyle;
                        }
                        if (soapMethod.paramStyle == SoapParameterStyle.Default)
                        {
                            soapMethod.paramStyle = SoapParameterStyle.Wrapped;
                        }
                    }
                }

                if (methodAttribute.binding.Length > 0)
                {
                    if (client)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.WebInvalidBindingPlacement, methodAttr.GetType().Name));
                    }
                    soapMethod.binding = WebServiceBindingReflector.GetAttribute(methodInfo, methodAttribute.binding);
                }

                WebMethodAttribute webMethodAttribute = WebMethodReflector.GetAttribute(methodInfo);
                soapMethod.name = webMethodAttribute.MessageName;
                if (soapMethod.name.Length == 0)
                {
                    soapMethod.name = methodInfo.Name;
                }

                string requestElementName;
                if (soapMethod.rpc)
                {
                    requestElementName = methodInfo.Name;
                }
                else
                {
                    requestElementName = methodAttribute.requestName.Length == 0 ? soapMethod.name : methodAttribute.requestName;
                }
                string requestNamespace = methodAttribute.requestNs;

                if (requestNamespace == null)
                {
                    if (soapMethod.binding != null && soapMethod.binding.Namespace != null && soapMethod.binding.Namespace.Length != 0)
                    {
                        requestNamespace = soapMethod.binding.Namespace;
                    }
                    else
                    {
                        requestNamespace = defaultNs;
                    }
                }

                string responseElementName = methodAttribute.responseName.Length == 0 ? soapMethod.name + "Response": methodAttribute.responseName;
                string responseNamespace   = methodAttribute.responseNs;

                if (responseNamespace == null)
                {
                    if (soapMethod.binding != null && soapMethod.binding.Namespace != null && soapMethod.binding.Namespace.Length != 0)
                    {
                        responseNamespace = soapMethod.binding.Namespace;
                    }
                    else
                    {
                        responseNamespace = defaultNs;
                    }
                }

                SoapParameterInfo[] inParameters  = ReflectParameters(methodInfo.InParameters, requestNamespace);
                SoapParameterInfo[] outParameters = ReflectParameters(methodInfo.OutParameters, responseNamespace);

                soapMethod.action = methodAttribute.action;
                if (soapMethod.action == null)
                {
                    soapMethod.action = GetDefaultAction(defaultNs, methodInfo);
                }
                soapMethod.methodInfo = methodInfo;

                if (soapMethod.oneWay)
                {
                    if (outParameters.Length > 0)
                    {
                        throw new ArgumentException(Res.GetString(Res.WebOneWayOutParameters), "methodInfo");
                    }
                    if (methodInfo.ReturnType != typeof(void))
                    {
                        throw new ArgumentException(Res.GetString(Res.WebOneWayReturnValue), "methodInfo");
                    }
                }

                XmlReflectionMember[] members = new XmlReflectionMember[inParameters.Length];
                for (int i = 0; i < members.Length; i++)
                {
                    SoapParameterInfo   soapParamInfo = inParameters[i];
                    XmlReflectionMember member        = new XmlReflectionMember();
                    member.MemberName = soapParamInfo.parameterInfo.Name;
                    member.MemberType = soapParamInfo.parameterInfo.ParameterType;
                    if (member.MemberType.IsByRef)
                    {
                        member.MemberType = member.MemberType.GetElementType();
                    }
                    member.XmlAttributes  = soapParamInfo.xmlAttributes;
                    member.SoapAttributes = soapParamInfo.soapAttributes;
                    members[i]            = member;
                }
                soapMethod.requestMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, soapMethod.rpc, soapMethod.use, soapMethod.paramStyle, requestElementName, requestNamespace, methodAttribute.requestNs == null, members, true);

                if (GetSoapServiceRoutingStyle(serviceAttr) == SoapServiceRoutingStyle.RequestElement &&
                    soapMethod.paramStyle == SoapParameterStyle.Bare &&
                    soapMethod.requestMappings.Count != 1)
                {
                    throw new ArgumentException(Res.GetString(Res.WhenUsingAMessageStyleOfParametersAsDocument0), "methodInfo");
                }

                string elementName      = "";
                string elementNamespace = "";
                if (soapMethod.paramStyle == SoapParameterStyle.Bare)
                {
                    if (soapMethod.requestMappings.Count == 1)
                    {
                        elementName      = soapMethod.requestMappings[0].ElementName;
                        elementNamespace = soapMethod.requestMappings[0].Namespace;
                    }
                    // else: can't route on request element -- we match on an empty qname,
                    //       normal rules apply for duplicates
                }
                else
                {
                    elementName      = soapMethod.requestMappings.ElementName;
                    elementNamespace = soapMethod.requestMappings.Namespace;
                }
                soapMethod.requestElementName = new XmlQualifiedName(elementName, elementNamespace);

                if (!soapMethod.oneWay)
                {
                    int             numOutParams = outParameters.Length;
                    int             count        = 0;
                    CodeIdentifiers identifiers  = null;
                    if (methodInfo.ReturnType != typeof(void))
                    {
                        numOutParams++;
                        count       = 1;
                        identifiers = new CodeIdentifiers();
                    }
                    members = new XmlReflectionMember[numOutParams];

                    for (int i = 0; i < outParameters.Length; i++)
                    {
                        SoapParameterInfo   soapParamInfo = outParameters[i];
                        XmlReflectionMember member        = new XmlReflectionMember();
                        member.MemberName = soapParamInfo.parameterInfo.Name;
                        member.MemberType = soapParamInfo.parameterInfo.ParameterType;
                        if (member.MemberType.IsByRef)
                        {
                            member.MemberType = member.MemberType.GetElementType();
                        }
                        member.XmlAttributes  = soapParamInfo.xmlAttributes;
                        member.SoapAttributes = soapParamInfo.soapAttributes;
                        members[count++]      = member;
                        if (identifiers != null)
                        {
                            identifiers.Add(member.MemberName, null);
                        }
                    }
                    if (methodInfo.ReturnType != typeof(void))
                    {
                        XmlReflectionMember member = new XmlReflectionMember();
                        member.MemberName    = identifiers.MakeUnique(soapMethod.name + "Result");
                        member.MemberType    = methodInfo.ReturnType;
                        member.IsReturnValue = true;

                        member.XmlAttributes         = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider);
                        member.XmlAttributes.XmlRoot = null; // Ignore XmlRoot attribute used by get/post
                        member.SoapAttributes        = new SoapAttributes(methodInfo.ReturnTypeCustomAttributeProvider);

                        members[0] = member;
                    }
                    soapMethod.responseMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, soapMethod.rpc, soapMethod.use, soapMethod.paramStyle, responseElementName, responseNamespace, methodAttribute.responseNs == null, members, false);
                }

                SoapExtensionAttribute[] extensionAttributes = (SoapExtensionAttribute[])methodInfo.GetCustomAttributes(typeof(SoapExtensionAttribute));
                soapMethod.extensions = new SoapReflectedExtension[extensionAttributes.Length];
                for (int i = 0; i < extensionAttributes.Length; i++)
                {
                    soapMethod.extensions[i] = new SoapReflectedExtension(extensionAttributes[i].ExtensionType, extensionAttributes[i]);
                }
                Array.Sort(soapMethod.extensions);

                SoapHeaderAttribute[] headerAttributes = (SoapHeaderAttribute[])methodInfo.GetCustomAttributes(typeof(SoapHeaderAttribute));
                Array.Sort(headerAttributes, new SoapHeaderAttributeComparer());
                Hashtable headerTypes = new Hashtable();
                soapMethod.headers = new SoapReflectedHeader[headerAttributes.Length];
                int       front      = 0;
                int       back       = soapMethod.headers.Length;
                ArrayList inHeaders  = new ArrayList();
                ArrayList outHeaders = new ArrayList();
                for (int i = 0; i < soapMethod.headers.Length; i++)
                {
                    SoapHeaderAttribute headerAttribute = headerAttributes[i];
                    SoapReflectedHeader soapHeader      = new SoapReflectedHeader();
                    Type declaringType = methodInfo.DeclaringType;
                    if ((soapHeader.memberInfo = declaringType.GetField(headerAttribute.MemberName)) != null)
                    {
                        soapHeader.headerType = ((FieldInfo)soapHeader.memberInfo).FieldType;
                    }
                    else if ((soapHeader.memberInfo = declaringType.GetProperty(headerAttribute.MemberName)) != null)
                    {
                        soapHeader.headerType = ((PropertyInfo)soapHeader.memberInfo).PropertyType;
                    }
                    else
                    {
                        throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderMissing);
                    }
                    if (soapHeader.headerType.IsArray)
                    {
                        soapHeader.headerType = soapHeader.headerType.GetElementType();
                        soapHeader.repeats    = true;
                        if (soapHeader.headerType != typeof(SoapUnknownHeader) && soapHeader.headerType != typeof(SoapHeader))
                        {
                            throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderType);
                        }
                    }
                    if (MemberHelper.IsStatic(soapHeader.memberInfo))
                    {
                        throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderStatic);
                    }
                    if (!MemberHelper.CanRead(soapHeader.memberInfo))
                    {
                        throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderRead);
                    }
                    if (!MemberHelper.CanWrite(soapHeader.memberInfo))
                    {
                        throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderWrite);
                    }
                    if (!typeof(SoapHeader).IsAssignableFrom(soapHeader.headerType))
                    {
                        throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderType);
                    }

                    SoapHeaderDirection direction = headerAttribute.Direction;
                    if (soapMethod.oneWay && (direction & (SoapHeaderDirection.Out | SoapHeaderDirection.Fault)) != 0)
                    {
                        throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderOneWayOut);
                    }
                    if (headerTypes.Contains(soapHeader.headerType))
                    {
                        SoapHeaderDirection prevDirection = (SoapHeaderDirection)headerTypes[soapHeader.headerType];
                        if ((prevDirection & direction) != 0)
                        {
                            throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebMultiplyDeclaredHeaderTypes);
                        }
                        headerTypes[soapHeader.headerType] = direction | prevDirection;
                    }
                    else
                    {
                        headerTypes[soapHeader.headerType] = direction;
                    }

                    if (soapHeader.headerType != typeof(SoapHeader) && soapHeader.headerType != typeof(SoapUnknownHeader))
                    {
                        XmlReflectionMember member = new XmlReflectionMember();
                        member.MemberName         = soapHeader.headerType.Name;
                        member.MemberType         = soapHeader.headerType;
                        member.OverrideIsNullable = true;

                        if ((direction & SoapHeaderDirection.In) != 0)
                        {
                            inHeaders.Add(member);
                        }
                        if ((direction & (SoapHeaderDirection.Out | SoapHeaderDirection.Fault)) != 0)
                        {
                            outHeaders.Add(member);
                        }

                        soapHeader.custom = true;
                    }
                    soapHeader.direction = direction;
                    // Put generic header mappings at the end of the list so they are found last during header processing
                    if (!soapHeader.custom)
                    {
                        soapMethod.headers[--back] = soapHeader;
                    }
                    else
                    {
                        soapMethod.headers[front++] = soapHeader;
                    }
                }
                soapMethod.inHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, soapMethod.use, SoapParameterStyle.Bare, "InHeaders", defaultNs, true, (XmlReflectionMember[])inHeaders.ToArray(typeof(XmlReflectionMember)), false);
                if (!soapMethod.oneWay)
                {
                    soapMethod.outHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, soapMethod.use, SoapParameterStyle.Bare, "OutHeaders", defaultNs, true, (XmlReflectionMember[])outHeaders.ToArray(typeof(XmlReflectionMember)), false);
                }

                return(soapMethod);
            }
            catch (Exception e) {
                throw new InvalidOperationException(Res.GetString(Res.WebReflectionErrorMethod, methodInfo.DeclaringType.Name, methodInfo.Name), e);
            }
        }
        public SoapServerType(Type type, WebServiceProtocols protocolsSupported) : base(type)
        {
            this.methods            = new Hashtable();
            this.duplicateMethods   = new Hashtable();
            this.protocolsSupported = protocolsSupported;
            bool flag = (protocolsSupported & WebServiceProtocols.HttpSoap) != WebServiceProtocols.Unknown;

            LogicalMethodInfo[] methods   = WebMethodReflector.GetMethods(type);
            ArrayList           list      = new ArrayList();
            WebServiceAttribute attribute = WebServiceReflector.GetAttribute(type);
            object soapServiceAttribute   = SoapReflector.GetSoapServiceAttribute(type);

            this.routingOnSoapAction     = SoapReflector.GetSoapServiceRoutingStyle(soapServiceAttribute) == SoapServiceRoutingStyle.SoapAction;
            this.serviceNamespace        = attribute.Namespace;
            this.serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(type);
            SoapReflectionImporter importer  = SoapReflector.CreateSoapImporter(this.serviceNamespace, this.serviceDefaultIsEncoded);
            XmlReflectionImporter  importer2 = SoapReflector.CreateXmlImporter(this.serviceNamespace, this.serviceDefaultIsEncoded);

            SoapReflector.IncludeTypes(methods, importer);
            WebMethodReflector.IncludeTypes(methods, importer2);
            SoapReflectedMethod[] methodArray = new SoapReflectedMethod[methods.Length];
            SoapExtensionTypeElementCollection soapExtensionTypes = WebServicesSection.Current.SoapExtensionTypes;
            ArrayList list2 = new ArrayList();
            ArrayList list3 = new ArrayList();

            for (int i = 0; i < soapExtensionTypes.Count; i++)
            {
                SoapExtensionTypeElement element = soapExtensionTypes[i];
                if (element != null)
                {
                    SoapReflectedExtension extension = new SoapReflectedExtension(element.Type, null, element.Priority);
                    if (element.Group == PriorityGroup.High)
                    {
                        list2.Add(extension);
                    }
                    else
                    {
                        list3.Add(extension);
                    }
                }
            }
            this.HighPriExtensions = (SoapReflectedExtension[])list2.ToArray(typeof(SoapReflectedExtension));
            this.LowPriExtensions  = (SoapReflectedExtension[])list3.ToArray(typeof(SoapReflectedExtension));
            Array.Sort <SoapReflectedExtension>(this.HighPriExtensions);
            Array.Sort <SoapReflectedExtension>(this.LowPriExtensions);
            this.HighPriExtensionInitializers = SoapReflectedExtension.GetInitializers(type, this.HighPriExtensions);
            this.LowPriExtensionInitializers  = SoapReflectedExtension.GetInitializers(type, this.LowPriExtensions);
            for (int j = 0; j < methods.Length; j++)
            {
                LogicalMethodInfo   methodInfo = methods[j];
                SoapReflectedMethod method     = SoapReflector.ReflectMethod(methodInfo, false, importer2, importer, attribute.Namespace);
                list.Add(method.requestMappings);
                if (method.responseMappings != null)
                {
                    list.Add(method.responseMappings);
                }
                list.Add(method.inHeaderMappings);
                if (method.outHeaderMappings != null)
                {
                    list.Add(method.outHeaderMappings);
                }
                methodArray[j] = method;
            }
            XmlMapping[] mappings = (XmlMapping[])list.ToArray(typeof(XmlMapping));
            TraceMethod  caller   = Tracing.On ? new TraceMethod(this, ".ctor", new object[] { type, protocolsSupported }) : null;

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

            for (int k = 0; k < methodArray.Length; k++)
            {
                SoapServerMethod    method3 = new SoapServerMethod();
                SoapReflectedMethod method4 = methodArray[k];
                method3.parameterSerializer = serializerArray[num3++];
                if (method4.responseMappings != null)
                {
                    method3.returnSerializer = serializerArray[num3++];
                }
                method3.inHeaderSerializer = serializerArray[num3++];
                if (method4.outHeaderMappings != null)
                {
                    method3.outHeaderSerializer = serializerArray[num3++];
                }
                method3.methodInfo            = method4.methodInfo;
                method3.action                = method4.action;
                method3.extensions            = method4.extensions;
                method3.extensionInitializers = SoapReflectedExtension.GetInitializers(method3.methodInfo, method4.extensions);
                method3.oneWay                = method4.oneWay;
                method3.rpc        = method4.rpc;
                method3.use        = method4.use;
                method3.paramStyle = method4.paramStyle;
                method3.wsiClaims  = (method4.binding == null) ? WsiProfiles.None : method4.binding.ConformsTo;
                ArrayList list4 = new ArrayList();
                ArrayList list5 = new ArrayList();
                for (int m = 0; m < method4.headers.Length; m++)
                {
                    SoapHeaderMapping   mapping = new SoapHeaderMapping();
                    SoapReflectedHeader header  = method4.headers[m];
                    mapping.memberInfo = header.memberInfo;
                    mapping.repeats    = header.repeats;
                    mapping.custom     = header.custom;
                    mapping.direction  = header.direction;
                    mapping.headerType = header.headerType;
                    if (mapping.direction == SoapHeaderDirection.In)
                    {
                        list4.Add(mapping);
                    }
                    else if (mapping.direction == SoapHeaderDirection.Out)
                    {
                        list5.Add(mapping);
                    }
                    else
                    {
                        list4.Add(mapping);
                        list5.Add(mapping);
                    }
                }
                method3.inHeaderMappings = (SoapHeaderMapping[])list4.ToArray(typeof(SoapHeaderMapping));
                if (method3.outHeaderSerializer != null)
                {
                    method3.outHeaderMappings = (SoapHeaderMapping[])list5.ToArray(typeof(SoapHeaderMapping));
                }
                if ((flag && !this.routingOnSoapAction) && method4.requestElementName.IsEmpty)
                {
                    throw new SoapException(System.Web.Services.Res.GetString("TheMethodDoesNotHaveARequestElementEither1", new object[] { method3.methodInfo.Name }), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"));
                }
                if (this.methods[method4.action] == null)
                {
                    this.methods[method4.action] = method3;
                }
                else
                {
                    if (flag && this.routingOnSoapAction)
                    {
                        SoapServerMethod method5 = (SoapServerMethod)this.methods[method4.action];
                        throw new SoapException(System.Web.Services.Res.GetString("TheMethodsAndUseTheSameSoapActionWhenTheService3", new object[] { method3.methodInfo.Name, method5.methodInfo.Name, method4.action }), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"));
                    }
                    this.duplicateMethods[method4.action] = method3;
                }
                if (this.methods[method4.requestElementName] == null)
                {
                    this.methods[method4.requestElementName] = method3;
                }
                else
                {
                    if (flag && !this.routingOnSoapAction)
                    {
                        SoapServerMethod method6 = (SoapServerMethod)this.methods[method4.requestElementName];
                        throw new SoapException(System.Web.Services.Res.GetString("TheMethodsAndUseTheSameRequestElementXmlns4", new object[] { method3.methodInfo.Name, method6.methodInfo.Name, method4.requestElementName.Name, method4.requestElementName.Namespace }), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"));
                    }
                    this.duplicateMethods[method4.requestElementName] = method3;
                }
            }
        }
 internal static SoapReflectedMethod ReflectMethod(LogicalMethodInfo methodInfo, bool client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, string defaultNs)
 {
     SoapReflectedMethod method2;
     try
     {
         string str2;
         string str4;
         string key = methodInfo.GetKey();
         SoapReflectedMethod method = new SoapReflectedMethod();
         MethodAttribute attribute = new MethodAttribute();
         object soapServiceAttribute = GetSoapServiceAttribute(methodInfo.DeclaringType);
         bool serviceDefaultIsEncoded = ServiceDefaultIsEncoded(soapServiceAttribute);
         object soapMethodAttribute = GetSoapMethodAttribute(methodInfo);
         if (soapMethodAttribute == null)
         {
             if (client)
             {
                 return null;
             }
             if (soapServiceAttribute is SoapRpcServiceAttribute)
             {
                 SoapRpcMethodAttribute attribute2 = new SoapRpcMethodAttribute {
                     Use = ((SoapRpcServiceAttribute) soapServiceAttribute).Use
                 };
                 soapMethodAttribute = attribute2;
             }
             else if (soapServiceAttribute is SoapDocumentServiceAttribute)
             {
                 SoapDocumentMethodAttribute attribute3 = new SoapDocumentMethodAttribute {
                     Use = ((SoapDocumentServiceAttribute) soapServiceAttribute).Use
                 };
                 soapMethodAttribute = attribute3;
             }
             else
             {
                 soapMethodAttribute = new SoapDocumentMethodAttribute();
             }
         }
         if (soapMethodAttribute is SoapRpcMethodAttribute)
         {
             SoapRpcMethodAttribute attribute4 = (SoapRpcMethodAttribute) soapMethodAttribute;
             method.rpc = true;
             method.use = attribute4.Use;
             method.oneWay = attribute4.OneWay;
             attribute.action = attribute4.Action;
             attribute.binding = attribute4.Binding;
             attribute.requestName = attribute4.RequestElementName;
             attribute.requestNs = attribute4.RequestNamespace;
             attribute.responseName = attribute4.ResponseElementName;
             attribute.responseNs = attribute4.ResponseNamespace;
         }
         else
         {
             SoapDocumentMethodAttribute attribute5 = (SoapDocumentMethodAttribute) soapMethodAttribute;
             method.rpc = false;
             method.use = attribute5.Use;
             method.paramStyle = attribute5.ParameterStyle;
             method.oneWay = attribute5.OneWay;
             attribute.action = attribute5.Action;
             attribute.binding = attribute5.Binding;
             attribute.requestName = attribute5.RequestElementName;
             attribute.requestNs = attribute5.RequestNamespace;
             attribute.responseName = attribute5.ResponseElementName;
             attribute.responseNs = attribute5.ResponseNamespace;
             if (method.use == SoapBindingUse.Default)
             {
                 if (soapServiceAttribute is SoapDocumentServiceAttribute)
                 {
                     method.use = ((SoapDocumentServiceAttribute) soapServiceAttribute).Use;
                 }
                 if (method.use == SoapBindingUse.Default)
                 {
                     method.use = SoapBindingUse.Literal;
                 }
             }
             if (method.paramStyle == SoapParameterStyle.Default)
             {
                 if (soapServiceAttribute is SoapDocumentServiceAttribute)
                 {
                     method.paramStyle = ((SoapDocumentServiceAttribute) soapServiceAttribute).ParameterStyle;
                 }
                 if (method.paramStyle == SoapParameterStyle.Default)
                 {
                     method.paramStyle = SoapParameterStyle.Wrapped;
                 }
             }
         }
         if (attribute.binding.Length > 0)
         {
             if (client)
             {
                 throw new InvalidOperationException(System.Web.Services.Res.GetString("WebInvalidBindingPlacement", new object[] { soapMethodAttribute.GetType().Name }));
             }
             method.binding = WebServiceBindingReflector.GetAttribute(methodInfo, attribute.binding);
         }
         WebMethodAttribute methodAttribute = methodInfo.MethodAttribute;
         method.name = methodAttribute.MessageName;
         if (method.name.Length == 0)
         {
             method.name = methodInfo.Name;
         }
         if (method.rpc)
         {
             str2 = ((attribute.requestName.Length == 0) || !client) ? methodInfo.Name : attribute.requestName;
         }
         else
         {
             str2 = (attribute.requestName.Length == 0) ? method.name : attribute.requestName;
         }
         string requestNs = attribute.requestNs;
         if (requestNs == null)
         {
             if (((method.binding != null) && (method.binding.Namespace != null)) && (method.binding.Namespace.Length != 0))
             {
                 requestNs = method.binding.Namespace;
             }
             else
             {
                 requestNs = defaultNs;
             }
         }
         if (method.rpc && (method.use != SoapBindingUse.Encoded))
         {
             str4 = methodInfo.Name + "Response";
         }
         else
         {
             str4 = (attribute.responseName.Length == 0) ? (method.name + "Response") : attribute.responseName;
         }
         string responseNs = attribute.responseNs;
         if (responseNs == null)
         {
             if (((method.binding != null) && (method.binding.Namespace != null)) && (method.binding.Namespace.Length != 0))
             {
                 responseNs = method.binding.Namespace;
             }
             else
             {
                 responseNs = defaultNs;
             }
         }
         SoapParameterInfo[] infoArray = ReflectParameters(methodInfo.InParameters, requestNs);
         SoapParameterInfo[] infoArray2 = ReflectParameters(methodInfo.OutParameters, responseNs);
         method.action = attribute.action;
         if (method.action == null)
         {
             method.action = GetDefaultAction(defaultNs, methodInfo);
         }
         method.methodInfo = methodInfo;
         if (method.oneWay)
         {
             if (infoArray2.Length > 0)
             {
                 throw new ArgumentException(System.Web.Services.Res.GetString("WebOneWayOutParameters"), "methodInfo");
             }
             if (methodInfo.ReturnType != typeof(void))
             {
                 throw new ArgumentException(System.Web.Services.Res.GetString("WebOneWayReturnValue"), "methodInfo");
             }
         }
         XmlReflectionMember[] members = new XmlReflectionMember[infoArray.Length];
         for (int i = 0; i < members.Length; i++)
         {
             SoapParameterInfo info = infoArray[i];
             XmlReflectionMember member = new XmlReflectionMember {
                 MemberName = info.parameterInfo.Name,
                 MemberType = info.parameterInfo.ParameterType
             };
             if (member.MemberType.IsByRef)
             {
                 member.MemberType = member.MemberType.GetElementType();
             }
             member.XmlAttributes = info.xmlAttributes;
             member.SoapAttributes = info.soapAttributes;
             members[i] = member;
         }
         method.requestMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, method.rpc, method.use, method.paramStyle, str2, requestNs, attribute.requestNs == null, members, true, false, key, client);
         if (((GetSoapServiceRoutingStyle(soapServiceAttribute) == SoapServiceRoutingStyle.RequestElement) && (method.paramStyle == SoapParameterStyle.Bare)) && (method.requestMappings.Count != 1))
         {
             throw new ArgumentException(System.Web.Services.Res.GetString("WhenUsingAMessageStyleOfParametersAsDocument0"), "methodInfo");
         }
         string name = "";
         string ns = "";
         if (method.paramStyle == SoapParameterStyle.Bare)
         {
             if (method.requestMappings.Count == 1)
             {
                 name = method.requestMappings[0].XsdElementName;
                 ns = method.requestMappings[0].Namespace;
             }
         }
         else
         {
             name = method.requestMappings.XsdElementName;
             ns = method.requestMappings.Namespace;
         }
         method.requestElementName = new XmlQualifiedName(name, ns);
         if (!method.oneWay)
         {
             int num2 = infoArray2.Length;
             int num3 = 0;
             CodeIdentifiers identifiers = null;
             if (methodInfo.ReturnType != typeof(void))
             {
                 num2++;
                 num3 = 1;
                 identifiers = new CodeIdentifiers();
             }
             members = new XmlReflectionMember[num2];
             for (int m = 0; m < infoArray2.Length; m++)
             {
                 SoapParameterInfo info2 = infoArray2[m];
                 XmlReflectionMember member2 = new XmlReflectionMember {
                     MemberName = info2.parameterInfo.Name,
                     MemberType = info2.parameterInfo.ParameterType
                 };
                 if (member2.MemberType.IsByRef)
                 {
                     member2.MemberType = member2.MemberType.GetElementType();
                 }
                 member2.XmlAttributes = info2.xmlAttributes;
                 member2.SoapAttributes = info2.soapAttributes;
                 members[num3++] = member2;
                 if (identifiers != null)
                 {
                     identifiers.Add(member2.MemberName, null);
                 }
             }
             if (methodInfo.ReturnType != typeof(void))
             {
                 XmlReflectionMember member3 = new XmlReflectionMember {
                     MemberName = identifiers.MakeUnique(method.name + "Result"),
                     MemberType = methodInfo.ReturnType,
                     IsReturnValue = true,
                     XmlAttributes = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider)
                 };
                 member3.XmlAttributes.XmlRoot = null;
                 member3.SoapAttributes = new SoapAttributes(methodInfo.ReturnTypeCustomAttributeProvider);
                 members[0] = member3;
             }
             method.responseMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, method.rpc, method.use, method.paramStyle, str4, responseNs, attribute.responseNs == null, members, false, false, key + ":Response", !client);
         }
         SoapExtensionAttribute[] customAttributes = (SoapExtensionAttribute[]) methodInfo.GetCustomAttributes(typeof(SoapExtensionAttribute));
         method.extensions = new SoapReflectedExtension[customAttributes.Length];
         for (int j = 0; j < customAttributes.Length; j++)
         {
             method.extensions[j] = new SoapReflectedExtension(customAttributes[j].ExtensionType, customAttributes[j]);
         }
         Array.Sort<SoapReflectedExtension>(method.extensions);
         SoapHeaderAttribute[] array = (SoapHeaderAttribute[]) methodInfo.GetCustomAttributes(typeof(SoapHeaderAttribute));
         Array.Sort(array, new SoapHeaderAttributeComparer());
         Hashtable hashtable = new Hashtable();
         method.headers = new SoapReflectedHeader[array.Length];
         int num6 = 0;
         int length = method.headers.Length;
         ArrayList list = new ArrayList();
         ArrayList list2 = new ArrayList();
         for (int k = 0; k < method.headers.Length; k++)
         {
             SoapHeaderAttribute attribute7 = array[k];
             SoapReflectedHeader header = new SoapReflectedHeader();
             Type declaringType = methodInfo.DeclaringType;
             header.memberInfo = declaringType.GetField(attribute7.MemberName);
             if (header.memberInfo != null)
             {
                 header.headerType = ((FieldInfo) header.memberInfo).FieldType;
             }
             else
             {
                 header.memberInfo = declaringType.GetProperty(attribute7.MemberName);
                 if (header.memberInfo == null)
                 {
                     throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderMissing");
                 }
                 header.headerType = ((PropertyInfo) header.memberInfo).PropertyType;
             }
             if (header.headerType.IsArray)
             {
                 header.headerType = header.headerType.GetElementType();
                 header.repeats = true;
                 if ((header.headerType != typeof(SoapUnknownHeader)) && (header.headerType != typeof(SoapHeader)))
                 {
                     throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderType");
                 }
             }
             if (MemberHelper.IsStatic(header.memberInfo))
             {
                 throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderStatic");
             }
             if (!MemberHelper.CanRead(header.memberInfo))
             {
                 throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderRead");
             }
             if (!MemberHelper.CanWrite(header.memberInfo))
             {
                 throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderWrite");
             }
             if (!typeof(SoapHeader).IsAssignableFrom(header.headerType))
             {
                 throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderType");
             }
             SoapHeaderDirection direction = attribute7.Direction;
             if (method.oneWay && ((direction & (SoapHeaderDirection.Fault | SoapHeaderDirection.Out)) != 0))
             {
                 throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderOneWayOut");
             }
             if (hashtable.Contains(header.headerType))
             {
                 SoapHeaderDirection direction2 = (SoapHeaderDirection) hashtable[header.headerType];
                 if ((direction2 & direction) != 0)
                 {
                     throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebMultiplyDeclaredHeaderTypes");
                 }
                 hashtable[header.headerType] = direction | direction2;
             }
             else
             {
                 hashtable[header.headerType] = direction;
             }
             if ((header.headerType != typeof(SoapHeader)) && (header.headerType != typeof(SoapUnknownHeader)))
             {
                 XmlReflectionMember member4 = new XmlReflectionMember {
                     MemberName = header.headerType.Name,
                     MemberType = header.headerType
                 };
                 XmlAttributes attributes = new XmlAttributes(header.headerType);
                 if (attributes.XmlRoot != null)
                 {
                     member4.XmlAttributes = new XmlAttributes();
                     XmlElementAttribute attribute8 = new XmlElementAttribute {
                         ElementName = attributes.XmlRoot.ElementName,
                         Namespace = attributes.XmlRoot.Namespace
                     };
                     member4.XmlAttributes.XmlElements.Add(attribute8);
                 }
                 member4.OverrideIsNullable = true;
                 if ((direction & SoapHeaderDirection.In) != 0)
                 {
                     list.Add(member4);
                 }
                 if ((direction & (SoapHeaderDirection.Fault | SoapHeaderDirection.Out)) != 0)
                 {
                     list2.Add(member4);
                 }
                 header.custom = true;
             }
             header.direction = direction;
             if (!header.custom)
             {
                 method.headers[--length] = header;
             }
             else
             {
                 method.headers[num6++] = header;
             }
         }
         method.inHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, method.use, SoapParameterStyle.Bare, str2 + "InHeaders", defaultNs, true, (XmlReflectionMember[]) list.ToArray(typeof(XmlReflectionMember)), false, true, key + ":InHeaders", client);
         if (!method.oneWay)
         {
             method.outHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, method.use, SoapParameterStyle.Bare, str4 + "OutHeaders", defaultNs, true, (XmlReflectionMember[]) list2.ToArray(typeof(XmlReflectionMember)), false, true, key + ":OutHeaders", !client);
         }
         method2 = method;
     }
     catch (Exception exception)
     {
         if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
         {
             throw;
         }
         throw new InvalidOperationException(System.Web.Services.Res.GetString("WebReflectionErrorMethod", new object[] { methodInfo.DeclaringType.Name, methodInfo.Name }), exception);
     }
     return method2;
 }