Exemple #1
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();
            }
        }
Exemple #2
0
 public static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     if ((mappings != null) && (mappings.Length != 0))
     {
         for (int i = 0; i < mappings.Length; i++)
         {
             SoapHeaderMapping mapping = mappings[i];
             if ((mapping.direction & direction) != 0)
             {
                 object obj2 = MemberHelper.GetValue(mapping.memberInfo, target);
                 if (mapping.repeats)
                 {
                     object[] objArray = (object[])obj2;
                     if (objArray != null)
                     {
                         for (int j = 0; j < objArray.Length; j++)
                         {
                             if (objArray[j] != null)
                             {
                                 headers.Add((SoapHeader)objArray[j]);
                             }
                         }
                     }
                 }
                 else if (obj2 != null)
                 {
                     headers.Add((SoapHeader)obj2);
                 }
             }
         }
     }
 }
 public static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     if ((mappings != null) && (mappings.Length != 0))
     {
         for (int i = 0; i < mappings.Length; i++)
         {
             SoapHeaderMapping mapping = mappings[i];
             if ((mapping.direction & direction) != 0)
             {
                 object obj2 = MemberHelper.GetValue(mapping.memberInfo, target);
                 if (mapping.repeats)
                 {
                     object[] objArray = (object[]) obj2;
                     if (objArray != null)
                     {
                         for (int j = 0; j < objArray.Length; j++)
                         {
                             if (objArray[j] != null)
                             {
                                 headers.Add((SoapHeader) objArray[j]);
                             }
                         }
                     }
                 }
                 else if (obj2 != null)
                 {
                     headers.Add((SoapHeader) obj2);
                 }
             }
         }
     }
 }
Exemple #4
0
 public static void SetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     bool[] flagArray = new bool[headers.Count];
     if (mappings != null)
     {
         for (int j = 0; j < mappings.Length; j++)
         {
             SoapHeaderMapping mapping = mappings[j];
             if ((mapping.direction & direction) != 0)
             {
                 if (mapping.repeats)
                 {
                     ArrayList list = new ArrayList();
                     for (int k = 0; k < headers.Count; k++)
                     {
                         SoapHeader header = headers[k];
                         if (!flagArray[k] && mapping.headerType.IsAssignableFrom(header.GetType()))
                         {
                             list.Add(header);
                             flagArray[k] = true;
                         }
                     }
                     MemberHelper.SetValue(mapping.memberInfo, target, list.ToArray(mapping.headerType));
                 }
                 else
                 {
                     bool flag = false;
                     for (int m = 0; m < headers.Count; m++)
                     {
                         SoapHeader header2 = headers[m];
                         if (!flagArray[m] && mapping.headerType.IsAssignableFrom(header2.GetType()))
                         {
                             if (flag)
                             {
                                 header2.DidUnderstand = false;
                             }
                             else
                             {
                                 flag = true;
                                 MemberHelper.SetValue(mapping.memberInfo, target, header2);
                                 flagArray[m] = true;
                             }
                         }
                     }
                 }
             }
         }
     }
     for (int i = 0; i < flagArray.Length; i++)
     {
         if (!flagArray[i])
         {
             SoapHeader header3 = headers[i];
             if (header3.MustUnderstand && !header3.DidUnderstand)
             {
                 throw new SoapHeaderException(System.Web.Services.Res.GetString("WebCannotUnderstandHeader", new object[] { GetHeaderElementName(header3) }), new XmlQualifiedName("MustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/"));
             }
         }
     }
 }
 internal static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     for (int i = 0; i < mappings.Length; i++)
     {
         SoapHeaderMapping mapping = mappings[i];
         if ((mapping.direction & direction) == 0)
         {
             continue;
         }
         object value = MemberHelper.GetValue(mapping.memberInfo, target);
         if (mapping.repeats)
         {
             object[] values = (object[])value;
             if (values == null)
             {
                 continue;
             }
             for (int j = 0; j < values.Length; j++)
             {
                 if (values[j] != null)
                 {
                     headers.Add((SoapHeader)values[j]);
                 }
             }
         }
         else
         {
             if (value != null)
             {
                 headers.Add((SoapHeader)value);
             }
         }
     }
 }
 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();
     }
 }
Exemple #7
0
        static int FindMapping(SoapHeaderMapping[] mappings, SoapHeader header, SoapHeaderDirection direction)
        {
            if (mappings == null || mappings.Length == 0)
            {
                return(-1);
            }
            Type headerType = header.GetType();

            for (int i = 0; i < mappings.Length; i++)
            {
                SoapHeaderMapping mapping = mappings[i];
                if ((mapping.direction & direction) == 0)
                {
                    continue;
                }
                if (!mapping.custom)
                {
                    continue;
                }
                if (mapping.headerType.IsAssignableFrom(headerType))
                {
                    return(i);
                }
            }
            return(-1);
        }
        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();
            }
        }
Exemple #9
0
		public static void SetHeaderMembers (
			SoapHeaderCollection headers,
			object target,
			SoapHeaderMapping [] mappings,
			SoapHeaderDirection direction,
			bool client)
		{
			throw new NotImplementedException ();
		}
Exemple #10
0
		public static void WriteHeaders (
			XmlWriter writer,
			XmlSerializer serializer,
			SoapHeaderCollection headers,
			SoapHeaderMapping [] mappings,
			SoapHeaderDirection direction,
			bool isEncoded,
			string defaultNS,
			bool serviceDefaultIsEncoded,
			string envelopeNS)
		{
			throw new NotImplementedException ();
		}
 private static int FindMapping(SoapHeaderMapping[] mappings, SoapHeader header, SoapHeaderDirection direction)
 {
     if ((mappings != null) && (mappings.Length != 0))
     {
         Type c = header.GetType();
         for (int i = 0; i < mappings.Length; i++)
         {
             SoapHeaderMapping mapping = mappings[i];
             if ((((mapping.direction & direction) != 0) && mapping.custom) && mapping.headerType.IsAssignableFrom(c))
             {
                 return i;
             }
         }
     }
     return -1;
 }
Exemple #12
0
 private static int FindMapping(SoapHeaderMapping[] mappings, SoapHeader header, SoapHeaderDirection direction)
 {
     if ((mappings != null) && (mappings.Length != 0))
     {
         Type c = header.GetType();
         for (int i = 0; i < mappings.Length; i++)
         {
             SoapHeaderMapping mapping = mappings[i];
             if ((((mapping.direction & direction) != 0) && mapping.custom) && mapping.headerType.IsAssignableFrom(c))
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
 static int FindMapping(SoapHeaderMapping[] mappings, SoapHeader header, SoapHeaderDirection direction) {
     if (mappings == null || mappings.Length == 0) return -1;
     Type headerType = header.GetType();
     for (int i = 0; i < mappings.Length; i++) {
         SoapHeaderMapping mapping = mappings[i];
         if ((mapping.direction & direction) == 0) continue;
         if (!mapping.custom) continue;
         if (mapping.headerType.IsAssignableFrom(headerType)) {
             return i;
         }
     }
     return -1;
 }
 public static void SetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     bool[] flagArray = new bool[headers.Count];
     if (mappings != null)
     {
         for (int j = 0; j < mappings.Length; j++)
         {
             SoapHeaderMapping mapping = mappings[j];
             if ((mapping.direction & direction) != 0)
             {
                 if (mapping.repeats)
                 {
                     ArrayList list = new ArrayList();
                     for (int k = 0; k < headers.Count; k++)
                     {
                         SoapHeader header = headers[k];
                         if (!flagArray[k] && mapping.headerType.IsAssignableFrom(header.GetType()))
                         {
                             list.Add(header);
                             flagArray[k] = true;
                         }
                     }
                     MemberHelper.SetValue(mapping.memberInfo, target, list.ToArray(mapping.headerType));
                 }
                 else
                 {
                     bool flag = false;
                     for (int m = 0; m < headers.Count; m++)
                     {
                         SoapHeader header2 = headers[m];
                         if (!flagArray[m] && mapping.headerType.IsAssignableFrom(header2.GetType()))
                         {
                             if (flag)
                             {
                                 header2.DidUnderstand = false;
                             }
                             else
                             {
                                 flag = true;
                                 MemberHelper.SetValue(mapping.memberInfo, target, header2);
                                 flagArray[m] = true;
                             }
                         }
                     }
                 }
             }
         }
     }
     for (int i = 0; i < flagArray.Length; i++)
     {
         if (!flagArray[i])
         {
             SoapHeader header3 = headers[i];
             if (header3.MustUnderstand && !header3.DidUnderstand)
             {
                 throw new SoapHeaderException(System.Web.Services.Res.GetString("WebCannotUnderstandHeader", new object[] { GetHeaderElementName(header3) }), new XmlQualifiedName("MustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/"));
             }
         }
     }
 }
        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);
            }
        }
        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();
        }
 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;
         }
     }
 }
Exemple #18
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);
            }
        }
        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;
                }
            }
        }
        public SoapServerType(Type type, WebServiceProtocols protocolsSupported) : base(type) {
            this.protocolsSupported = protocolsSupported;
            bool soap11 = (protocolsSupported & WebServiceProtocols.HttpSoap) != 0;
            bool soap12 = (protocolsSupported & WebServiceProtocols.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];

            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];
                if (element == null)
                    continue;
                SoapReflectedExtension extension = new SoapReflectedExtension(element.Type, null, element.Priority);
                if (element.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);
 
            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;
            }
            
            XmlMapping[] xmlMappings = (XmlMapping[])mappings.ToArray(typeof(XmlMapping));
            TraceMethod caller = Tracing.On ? new TraceMethod(this, ".ctor", type, protocolsSupported) : null;
            if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceCreateSerializer), caller, new TraceMethod(typeof(XmlSerializer), "FromMappings", xmlMappings, this.Evidence));
            XmlSerializer[] serializers = null;
            if (AppDomain.CurrentDomain.IsHomogenous) {
                serializers = XmlSerializer.FromMappings(xmlMappings);
            }
            else {
#pragma warning disable 618 // If we're in a non-homogenous domain, legacy CAS mode is enabled, so passing through evidence will not fail
                serializers = XmlSerializer.FromMappings((xmlMappings), this.Evidence);
#pragma warning restore 618
            }
            if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceCreateSerializer), caller);
            
            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;
                serverMethod.wsiClaims = soapMethod.binding == null ? WsiProfiles.None : soapMethod.binding.ConformsTo;
                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.Code.Client, 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.Code.Client, 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.Code.Client, Soap.Namespace));
                    }
                    duplicateMethods[soapMethod.requestElementName] = serverMethod;
                }
            }
        }
Exemple #21
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);
            }
        }
Exemple #22
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;
                }
            }
        }
 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);
     }
 }
        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);
            }
        }
 internal static void SetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client)
 {
     bool[] headerHandled = new bool[headers.Count];
     for (int i = 0; i < mappings.Length; i++)
     {
         SoapHeaderMapping mapping = mappings[i];
         if ((mapping.direction & direction) == 0)
         {
             continue;
         }
         if (mapping.repeats)
         {
             ArrayList list = new ArrayList();
             for (int j = 0; j < headers.Count; j++)
             {
                 SoapHeader header = headers[j];
                 if (headerHandled[j])
                 {
                     continue;
                 }
                 if (mapping.headerType.IsAssignableFrom(header.GetType()))
                 {
                     list.Add(header);
                     headerHandled[j] = true;
                 }
             }
             MemberHelper.SetValue(mapping.memberInfo, target, list.ToArray(mapping.headerType));
         }
         else
         {
             bool handled = false;
             for (int j = 0; j < headers.Count; j++)
             {
                 SoapHeader header = headers[j];
                 if (headerHandled[j])
                 {
                     continue;
                 }
                 if (mapping.headerType.IsAssignableFrom(header.GetType()))
                 {
                     if (handled)
                     {
                         header.DidUnderstand = false;
                         continue;
                     }
                     handled = true;
                     MemberHelper.SetValue(mapping.memberInfo, target, header);
                     headerHandled[j] = true;
                 }
             }
         }
     }
     if (client)
     {
         for (int i = 0; i < headerHandled.Length; i++)
         {
             if (!headerHandled[i])
             {
                 SoapHeader header = headers[i];
                 if (header.MustUnderstand && !header.DidUnderstand)
                 {
                     throw new SoapHeaderException(Res.GetString(Res.WebCannotUnderstandHeader, GetHeaderElementName(header)),
                                                   new XmlQualifiedName(Soap.MustUnderstandCode, Soap.Namespace));
                 }
             }
         }
     }
 }
        // return first missing header name;
        public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders) {
            string missingHeader = null;
            reader.MoveToContent();
            if (!reader.IsStartElement(Soap.Element.Header, envelopeNS)) {
                if (checkRequiredHeaders && mappings != null && mappings.Length > 0)
                    missingHeader = GetHeaderElementName(mappings[0].headerType);
                return missingHeader;
            }
            if (reader.IsEmptyElement) { reader.Skip(); return missingHeader; }

            this.unknownHeaders = new SoapHeaderCollection();
            this.unreferencedHeaders = new SoapHeaderCollection();
            // thread hash code is used to differentiate between deserializations in event callbacks
            this.currentThread = Thread.CurrentThread.GetHashCode();
            this.envelopeNS = envelopeNS;

            int depth = reader.Depth;
            reader.ReadStartElement();
            reader.MoveToContent();

            XmlDeserializationEvents events = new XmlDeserializationEvents();
            events.OnUnknownElement = new XmlElementEventHandler(this.OnUnknownElement);
            events.OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject);

            TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders") : null;
            if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceReadHeaders), caller, new TraceMethod(serializer, "Deserialize", reader, encodingStyle));
            object[] headerValues = (object[])serializer.Deserialize(reader, encodingStyle, events);
            if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceReadHeaders), caller);
            for (int i = 0; i < headerValues.Length; i++) {
                if (headerValues[i] != null) {
                    SoapHeader header = (SoapHeader)headerValues[i];
                    header.DidUnderstand = true;
                    headers.Add(header);
                }
                else if (checkRequiredHeaders) {
                    // run time check for R2738 A MESSAGE MUST include all soapbind:headers specified on a wsdl:input or wsdl:output of a wsdl:operationwsdl:binding that describes it. 
                    if (missingHeader == null)
                        missingHeader = GetHeaderElementName(mappings[i].headerType);
                }
            }
            this.currentThread = 0;
            this.envelopeNS = null;

            foreach (SoapHeader header in this.unreferencedHeaders) {
                headers.Add(header);
            }
            this.unreferencedHeaders = null;

            foreach (SoapHeader header in this.unknownHeaders) {
                headers.Add(header);
            }
            this.unknownHeaders = null;

            // Consume soap:Body and soap:Envelope closing tags
            while (depth < reader.Depth && reader.Read()) {
                // Nothing, just read on
            }
            // consume end tag
            if (reader.NodeType == XmlNodeType.EndElement) {
                reader.Read();
            }

            return missingHeader;
        }
 public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders)
 {
     string headerElementName = null;
     reader.MoveToContent();
     if (!reader.IsStartElement("Header", envelopeNS))
     {
         if ((checkRequiredHeaders && (mappings != null)) && (mappings.Length > 0))
         {
             headerElementName = GetHeaderElementName(mappings[0].headerType);
         }
         return headerElementName;
     }
     if (reader.IsEmptyElement)
     {
         reader.Skip();
         return headerElementName;
     }
     this.unknownHeaders = new SoapHeaderCollection();
     this.unreferencedHeaders = new SoapHeaderCollection();
     this.currentThread = Thread.CurrentThread.GetHashCode();
     this.envelopeNS = envelopeNS;
     int depth = reader.Depth;
     reader.ReadStartElement();
     reader.MoveToContent();
     XmlDeserializationEvents events = new XmlDeserializationEvents {
         OnUnknownElement = new XmlElementEventHandler(this.OnUnknownElement),
         OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject)
     };
     TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders", new object[0]) : null;
     if (Tracing.On)
     {
         Tracing.Enter(Tracing.TraceId("TraceReadHeaders"), caller, new TraceMethod(serializer, "Deserialize", new object[] { reader, encodingStyle }));
     }
     object[] objArray = (object[]) serializer.Deserialize(reader, encodingStyle, events);
     if (Tracing.On)
     {
         Tracing.Exit(Tracing.TraceId("TraceReadHeaders"), caller);
     }
     for (int i = 0; i < objArray.Length; i++)
     {
         if (objArray[i] != null)
         {
             SoapHeader header = (SoapHeader) objArray[i];
             header.DidUnderstand = true;
             headers.Add(header);
         }
         else if (checkRequiredHeaders && (headerElementName == null))
         {
             headerElementName = GetHeaderElementName(mappings[i].headerType);
         }
     }
     this.currentThread = 0;
     this.envelopeNS = null;
     foreach (SoapHeader header2 in this.unreferencedHeaders)
     {
         headers.Add(header2);
     }
     this.unreferencedHeaders = null;
     foreach (SoapHeader header3 in this.unknownHeaders)
     {
         headers.Add(header3);
     }
     this.unknownHeaders = null;
     while ((depth < reader.Depth) && reader.Read())
     {
     }
     if (reader.NodeType == XmlNodeType.EndElement)
     {
         reader.Read();
     }
     return headerElementName;
 }
 public static void SetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client) {
     bool[] headerHandled = new bool[headers.Count];
     if (mappings != null) {
         for (int i = 0; i < mappings.Length; i++) {
             SoapHeaderMapping mapping = mappings[i];
             if ((mapping.direction & direction) == 0) continue;
             if (mapping.repeats) {
                 ArrayList list = new ArrayList();
                 for (int j = 0; j < headers.Count; j++) {
                     SoapHeader header = headers[j];
                     if (headerHandled[j]) continue;
                     if (mapping.headerType.IsAssignableFrom(header.GetType())) {
                         list.Add(header);
                         headerHandled[j] = true;
                     }
                 }
                 MemberHelper.SetValue(mapping.memberInfo, target, list.ToArray(mapping.headerType));
             }
             else {
                 bool handled = false;
                 for (int j = 0; j < headers.Count; j++) {
                     SoapHeader header = headers[j];
                     if (headerHandled[j]) continue;
                     if (mapping.headerType.IsAssignableFrom(header.GetType())) {
                         if (handled) {
                             header.DidUnderstand = false;
                             continue;
                         }
                         handled = true;
                         MemberHelper.SetValue(mapping.memberInfo, target, header);
                         headerHandled[j] = true;
                     }
                 }
             }
         }
     }
     for (int i = 0; i < headerHandled.Length; i++) {
         if (!headerHandled[i]) {
             SoapHeader header = headers[i];
             if (header.MustUnderstand && !header.DidUnderstand) {
                 throw new SoapHeaderException(Res.GetString(Res.WebCannotUnderstandHeader, GetHeaderElementName(header)),
                     new XmlQualifiedName(Soap.Code.MustUnderstand, Soap.Namespace));
             }
         }
     }
 }
 public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS)
 {
     if (headers.Count != 0)
     {
         SoapProtocolVersion version;
         string str;
         writer.WriteStartElement("Header", envelopeNS);
         if (envelopeNS == "http://www.w3.org/2003/05/soap-envelope")
         {
             version = SoapProtocolVersion.Soap12;
             str = "http://www.w3.org/2003/05/soap-encoding";
         }
         else
         {
             version = SoapProtocolVersion.Soap11;
             str = "http://schemas.xmlsoap.org/soap/encoding/";
         }
         int num = 0;
         ArrayList list = new ArrayList();
         SoapHeader[] o = new SoapHeader[mappings.Length];
         bool[] flagArray = new bool[o.Length];
         for (int i = 0; i < headers.Count; i++)
         {
             SoapHeader header = headers[i];
             if (header != null)
             {
                 header.version = version;
                 if (header is SoapUnknownHeader)
                 {
                     list.Add(header);
                     num++;
                 }
                 else
                 {
                     int num3;
                     if (((num3 = FindMapping(mappings, header, direction)) >= 0) && !flagArray[num3])
                     {
                         o[num3] = header;
                         flagArray[num3] = true;
                     }
                     else
                     {
                         list.Add(header);
                     }
                 }
             }
         }
         int num4 = list.Count - num;
         if (isEncoded && (num4 > 0))
         {
             SoapHeader[] array = new SoapHeader[mappings.Length + num4];
             o.CopyTo(array, 0);
             int length = mappings.Length;
             for (int k = 0; k < list.Count; k++)
             {
                 if (!(list[k] is SoapUnknownHeader))
                 {
                     array[length++] = (SoapHeader) list[k];
                 }
             }
             o = array;
         }
         TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders", new object[0]) : null;
         if (Tracing.On)
         {
             object[] args = new object[5];
             args[0] = writer;
             args[1] = o;
             args[3] = isEncoded ? str : null;
             args[4] = "h_";
             Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(serializer, "Serialize", args));
         }
         serializer.Serialize(writer, o, null, isEncoded ? str : null, "h_");
         if (Tracing.On)
         {
             Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller);
         }
         foreach (SoapHeader header2 in list)
         {
             if (header2 is SoapUnknownHeader)
             {
                 SoapUnknownHeader header3 = (SoapUnknownHeader) header2;
                 if (header3.Element != null)
                 {
                     header3.Element.WriteTo(writer);
                 }
             }
             else if (!isEncoded)
             {
                 string literalNamespace = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded);
                 XmlSerializer target = new XmlSerializer(header2.GetType(), literalNamespace);
                 if (Tracing.On)
                 {
                     Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(target, "Serialize", new object[] { writer, header2 }));
                 }
                 target.Serialize(writer, header2);
                 if (Tracing.On)
                 {
                     Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller);
                 }
             }
         }
         for (int j = 0; j < headers.Count; j++)
         {
             SoapHeader header4 = headers[j];
             if (header4 != null)
             {
                 header4.version = SoapProtocolVersion.Default;
             }
         }
         writer.WriteEndElement();
         writer.Flush();
     }
 }
 public static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client) {
     if (mappings == null || mappings.Length == 0) return;
     for (int i = 0; i < mappings.Length; i++) {
         SoapHeaderMapping mapping = mappings[i];
         if ((mapping.direction & direction) == 0) continue;
         object value = MemberHelper.GetValue(mapping.memberInfo, target);
         if (mapping.repeats) {
             object[] values = (object[])value;
             if (values == null) continue;
             for (int j = 0; j < values.Length; j++) {
                 if (values[j] != null) headers.Add((SoapHeader)values[j]);
             }
         }
         else {
             if (value != null) headers.Add((SoapHeader)value);
         }
     }
 }
        public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS) {
            if (headers.Count == 0) return;
            writer.WriteStartElement(Soap.Element.Header, envelopeNS);
            SoapProtocolVersion version;
            string encodingStyle;
            if (envelopeNS == Soap12.Namespace) {
                version = SoapProtocolVersion.Soap12;
                encodingStyle = Soap12.Encoding;
            }
            else {
                version = SoapProtocolVersion.Soap11;
                encodingStyle = Soap.Encoding;
            }

            int unknownHeaderCount = 0;
            ArrayList otherHeaders = new ArrayList();
            SoapHeader[] headerArray = new SoapHeader[mappings.Length];
            bool[] headerSet = new bool[headerArray.Length];
            for (int i = 0; i < headers.Count; i++) {
                SoapHeader header = headers[i];
                if (header == null) continue;
                int headerPosition;
                header.version = version;
                if (header is SoapUnknownHeader) {
                    otherHeaders.Add(header);
                    unknownHeaderCount++;
                }
                else if ((headerPosition = FindMapping(mappings, header, direction)) >= 0 && !headerSet[headerPosition]) {
                    headerArray[headerPosition] = header;
                    headerSet[headerPosition] = true;
                }
                else {
                    otherHeaders.Add(header);
                }
            }
            int otherHeaderCount = otherHeaders.Count - unknownHeaderCount;
            if (isEncoded && otherHeaderCount > 0) {
                SoapHeader[] newHeaderArray = new SoapHeader[mappings.Length + otherHeaderCount];
                headerArray.CopyTo(newHeaderArray, 0);

                // fill in the non-statically known headers (otherHeaders) starting after the statically-known ones
                int count = mappings.Length;
                for (int i = 0; i < otherHeaders.Count; i++) {
                    if (!(otherHeaders[i] is SoapUnknownHeader))
                        newHeaderArray[count++] = (SoapHeader)otherHeaders[i];
                }

                headerArray = newHeaderArray;
            }

            TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders") : null;
            if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(serializer, "Serialize", writer, headerArray, null, isEncoded ? encodingStyle : null, "h_"));
            serializer.Serialize(writer, headerArray, null, isEncoded ? encodingStyle : null, "h_");
            if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller);

            foreach (SoapHeader header in otherHeaders) {
                if (header is SoapUnknownHeader) {
                    SoapUnknownHeader unknown = (SoapUnknownHeader)header;
                    if (unknown.Element != null)
                        unknown.Element.WriteTo(writer);
                }
                else if (!isEncoded) { // encoded headers already appended to members mapping
                    string ns = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded);
                    XmlSerializer headerSerializer = new XmlSerializer(header.GetType(), ns);

                    if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(headerSerializer, "Serialize", writer, header));
                    headerSerializer.Serialize(writer, header);
                    if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller);
                }
            }

            // reset the soap version
            for (int i = 0; i < headers.Count; i++) {
                SoapHeader header = headers[i];
                if (header != null)
                    header.version = SoapProtocolVersion.Default;
            }

            writer.WriteEndElement();
            writer.Flush();
        }
Exemple #32
0
		public string ReadHeaders (
			XmlReader reader,
			XmlSerializer serializer,
			SoapHeaderCollection headers,
			SoapHeaderMapping [] mappings,
			SoapHeaderDirection direction,
			string envelopeNS,
			string encodingStyle,
			bool checkRequiredHeaders)
		{
			throw new NotImplementedException ();
		}