private XmlTypeMapping Map (Type t, SoapAttributeOverrides overrides)
		{
			SoapReflectionImporter ri = new SoapReflectionImporter(overrides);
			XmlTypeMapping tm = ri.ImportTypeMapping(t);

			return tm;
		}
		private XmlTypeMapping Map (Type t, string ns)
		{
			SoapReflectionImporter ri = new SoapReflectionImporter (ns);
			XmlTypeMapping tm = ri.ImportTypeMapping (t);

			return tm;
		}
Example #3
0
		XmlTypeMapping GetEncodedTypeMapping ()
		{
			SoapReflectionImporter sri = new SoapReflectionImporter ();
			sri.IncludeType (typeof(UknTestPart));
			sri.IncludeType (typeof(AnotherTestPart));
			sri.IncludeType (typeof(DblStringContainer));
			return sri.ImportTypeMapping (typeof(Test));
		}
		private object DeserializeEncoded (Type t, XmlReader xr)
		{
			SoapReflectionImporter im = new SoapReflectionImporter ();
			XmlTypeMapping tm = im.ImportTypeMapping (t);
			XmlSerializer ser = new XmlSerializer (tm);
			result = ser.Deserialize (xr);
			return result;
		}
Example #5
0
		private XmlSchemas Export (Type type, SoapAttributeOverrides overrides, string defaultNamespace)
		{
			SoapReflectionImporter ri = new SoapReflectionImporter (overrides, defaultNamespace);
			XmlSchemas schemas = new XmlSchemas ();
			SoapSchemaExporter sx = new SoapSchemaExporter (schemas);
			XmlTypeMapping tm = ri.ImportTypeMapping (type);
			sx.ExportTypeMapping (tm);
			return schemas;
		}
		private XmlMembersMapping MembersMap (Type t, SoapAttributeOverrides overrides, 
			XmlReflectionMember [] members, bool inContainer, bool writeAccessors)
		{
			SoapReflectionImporter ri = new SoapReflectionImporter (overrides);
			XmlMembersMapping mm = ri.ImportMembersMapping (null, null, members, 
				inContainer, writeAccessors);
			
			return mm;
		}
		public static void Generate (string configFileName, string outputPath)
		{
			SerializationCodeGeneratorConfiguration cnf = null;
			StreamReader sr = new StreamReader (configFileName);
			try
			{
				XmlReflectionImporter ri = new XmlReflectionImporter ();
				ri.AllowPrivateTypes = true;
				XmlSerializer ser = new XmlSerializer (ri.ImportTypeMapping (typeof (SerializationCodeGeneratorConfiguration)));
				cnf = (SerializationCodeGeneratorConfiguration) ser.Deserialize (sr);
			}
			finally
			{
				sr.Close ();
			}
			
			if (outputPath == null) outputPath = "";
			
			CodeIdentifiers ids = new CodeIdentifiers ();
			if (cnf.Serializers != null)
			{
				foreach (SerializerInfo info in cnf.Serializers)
				{					
					Type type;
					if (info.Assembly != null)
					{
						Assembly asm;
						try {
							asm = Assembly.Load (info.Assembly);
						} catch {
							asm = Assembly.LoadFrom (info.Assembly);
						}
						type = asm.GetType (info.ClassName, true);
					}
					else
						type = Type.GetType (info.ClassName);
					
					if (type == null) throw new InvalidOperationException ("Type " + info.ClassName + " not found");
					
					string file = info.OutFileName;
					if (file == null || file.Length == 0) {
						int i = info.ClassName.LastIndexOf (".");
						if (i != -1) file = info.ClassName.Substring (i+1);
						else file = info.ClassName;
						file = ids.AddUnique (file, type) + "Serializer.cs";
					}
					StreamWriter writer = new StreamWriter (Path.Combine (outputPath, file));
					
					try
					{
						XmlTypeMapping map;
						
						if (info.SerializationFormat == SerializationFormat.Literal) {
							XmlReflectionImporter ri = new XmlReflectionImporter ();
							map = ri.ImportTypeMapping (type);
						}
						else {
							SoapReflectionImporter ri = new SoapReflectionImporter ();
							map = ri.ImportTypeMapping (type);
						}
						
						SerializationCodeGenerator gen = new SerializationCodeGenerator (map, info);
						gen.GenerateSerializers (writer);
					}
					finally
					{
						writer.Close ();
					}
				}
			}
		}
Example #8
0
		static XmlTypeMapping CreateSoapMapping (Type type, SoapAttributeOverrides ao, string defaultNamespace)
		{
			SoapReflectionImporter importer = new SoapReflectionImporter (ao, defaultNamespace);
			return importer.ImportTypeMapping (type);
		}
Example #9
0
		static XmlTypeMapping CreateSoapMapping (Type type, SoapAttributeOverrides ao)
		{
			SoapReflectionImporter importer = new SoapReflectionImporter (ao);
			return importer.ImportTypeMapping (type);
		}
Example #10
0
		static XmlTypeMapping CreateSoapMapping (Type type)
		{
			SoapReflectionImporter importer = new SoapReflectionImporter ();
			return importer.ImportTypeMapping (type);
		}
Example #11
0
		public void TestSerializeArrayEnc ()
		{
			SoapReflectionImporter imp = new SoapReflectionImporter ();
			XmlTypeMapping map = imp.ImportTypeMapping (typeof (ArrayClass));
			XmlSerializer ser = new XmlSerializer (map);
			StringWriter sw = new StringWriter ();
			XmlTextWriter tw = new XmlTextWriter (sw);
			tw.WriteStartElement ("aa");
			ser.Serialize (tw, new ArrayClass ());
			tw.WriteEndElement ();
		}
Example #12
0
		XmlTypeMapping ReflectType (TypeData typeData, string ns)
		{
			if (!encodedFormat)
			{
				if (auxXmlRefImporter == null) auxXmlRefImporter = new XmlReflectionImporter ();
				return auxXmlRefImporter.ImportTypeMapping (typeData, ns);
			}
			else
			{
				if (auxSoapRefImporter == null) auxSoapRefImporter = new SoapReflectionImporter ();
				return auxSoapRefImporter.ImportTypeMapping (typeData, ns);
			}
		}
 internal XmlSerializerImporter(string defaultNs)
 {
     this.defaultNs = defaultNs;
     this.xmlImporter = null;
     this.soapImporter = null;
 }
 static XmlMembersMapping ImportMembersMapping(XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, bool serviceDefaultIsEncoded, bool rpc, SoapBindingUse use, SoapParameterStyle paramStyle, 
     string elementName, string elementNamespace, bool nsIsDefault, XmlReflectionMember[] members, bool validate, bool openModel, string key, bool writeAccess) {
     XmlMembersMapping mapping = null;
     if (use == SoapBindingUse.Encoded) {
         string ns = (!rpc && paramStyle != SoapParameterStyle.Bare && nsIsDefault) ? GetEncodedNamespace(elementNamespace, serviceDefaultIsEncoded) : elementNamespace;
         mapping = soapImporter.ImportMembersMapping(elementName, ns, members, rpc || paramStyle != SoapParameterStyle.Bare, rpc, validate, writeAccess ? XmlMappingAccess.Write : XmlMappingAccess.Read);
     }
     else {
         string ns = nsIsDefault ? GetLiteralNamespace(elementNamespace, serviceDefaultIsEncoded) : elementNamespace;
         mapping = xmlImporter.ImportMembersMapping(elementName, ns, members, paramStyle != SoapParameterStyle.Bare, rpc, openModel, writeAccess ? XmlMappingAccess.Write : XmlMappingAccess.Read);
     }
     if (mapping != null) {
         mapping.SetKey(key);
     }
     return mapping;
 }
        internal static SoapReflectedMethod ReflectMethod(LogicalMethodInfo methodInfo, bool client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, string defaultNs) {
            try {
                string methodId = methodInfo.GetKey();
                SoapReflectedMethod soapMethod = new SoapReflectedMethod();
                MethodAttribute methodAttribute = new MethodAttribute();

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

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

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

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

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

                WebMethodAttribute webMethodAttribute = methodInfo.MethodAttribute;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                }

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

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

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

                        soapHeader.custom = true;
                    }
                    soapHeader.direction = direction;
                    // Put generic header mappings at the end of the list so they are found last during header processing
                    if (!soapHeader.custom) {
                        soapMethod.headers[--back] = soapHeader;
                    }
                    else {
                        soapMethod.headers[front++] = soapHeader;
                    }
                }
                soapMethod.inHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, soapMethod.use, SoapParameterStyle.Bare, requestElementName + "InHeaders", defaultNs, true, (XmlReflectionMember[]) inHeaders.ToArray(typeof(XmlReflectionMember)), false, true, methodId + ":InHeaders", client);
                if (!soapMethod.oneWay)
                    soapMethod.outHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, soapMethod.use, SoapParameterStyle.Bare, responseElementName + "OutHeaders", defaultNs, true, (XmlReflectionMember[]) outHeaders.ToArray(typeof(XmlReflectionMember)), false, true, methodId + ":OutHeaders", !client);
                
                return soapMethod;
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }
                throw new InvalidOperationException(Res.GetString(Res.WebReflectionErrorMethod, methodInfo.DeclaringType.Name, methodInfo.Name), e);
            }
        }
 internal static void IncludeTypes(LogicalMethodInfo method, SoapReflectionImporter importer) {
     if (method.Declaration != null) {
         importer.IncludeTypes(method.Declaration.DeclaringType);
         importer.IncludeTypes(method.Declaration);
     }
     importer.IncludeTypes(method.DeclaringType);
     importer.IncludeTypes(method.CustomAttributeProvider);
 }
 internal static void IncludeTypes(LogicalMethodInfo[] methods, SoapReflectionImporter importer) {
     for (int i = 0; i < methods.Length; i++) {
         LogicalMethodInfo method = methods[i];
         IncludeTypes(method, importer);
     }
 }
Example #18
0
		[Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
/*
#if NET_2_0
		[Category ("NotWorking")] // minOccurs is 1 on Mono
#endif
 */
		public void ExportClass_SimpleClass_Array ()
		{
			SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
			SoapAttributes attr = new SoapAttributes ();
			SoapElementAttribute element = new SoapElementAttribute ();
			element.ElementName = "saying";
			element.IsNullable = true;
			attr.SoapElement = element;
			overrides.Add (typeof (SimpleClass), "something", attr);

			SoapReflectionImporter ri = new SoapReflectionImporter (overrides, "NSSimpleClassArray");
			XmlSchemas schemas = new XmlSchemas ();
			SoapSchemaExporter sx = new SoapSchemaExporter (schemas);
			XmlTypeMapping tm = ri.ImportTypeMapping (typeof (SimpleClass[]));
			sx.ExportTypeMapping (tm);

			Assert.AreEqual (1, schemas.Count, "#1");

			StringWriter sw = new StringWriter ();
			schemas[0].Write (sw);

			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
#if NET_2_0
				"<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
#else
				"<xs:schema xmlns:tns=\"NSSimpleClassArray\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
#endif
				"  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
				"  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
				"  <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
				"    <xs:complexContent mixed=\"false\">{0}" +
				"      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
				"        <xs:attribute d5p1:arrayType=\"tns:SimpleClass[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
				"      </xs:restriction>{0}" +
				"    </xs:complexContent>{0}" +
				"  </xs:complexType>{0}" +
				"  <xs:complexType name=\"SimpleClass\">{0}" +
				"    <xs:sequence>{0}" +
#if NET_2_0
				"      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
#else
				"      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" type=\"xs:string\" />{0}" +
#endif
				"    </xs:sequence>{0}" +
				"  </xs:complexType>{0}" +
				"</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
		}
Example #19
0
		//
		// Constructor
		//
		public SoapMethodStubInfo (TypeStubInfo typeStub, LogicalMethodInfo source, object kind, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter)
		: base (typeStub, source)
		{
			SoapTypeStubInfo parent = (SoapTypeStubInfo) typeStub;
			XmlElementAttribute optional_ns = null;

			if (kind == null) {
				Use = parent.LogicalType.BindingUse;
				RequestName = "";
				RequestNamespace = "";
				ResponseName = "";
				ResponseNamespace = "";
				ParameterStyle = parent.ParameterStyle;
				SoapBindingStyle = parent.SoapBindingStyle;
				OneWay = false;
// disabled (see bug #332150)
//#if NET_2_0
//				if (parent.Type != source.DeclaringType)
//					Binding = source.DeclaringType.Name + parent.ProtocolName;
//#endif
			}
			else if (kind is SoapDocumentMethodAttribute){
				SoapDocumentMethodAttribute dma = (SoapDocumentMethodAttribute) kind;
				
				Use = dma.Use;
				if (Use == SoapBindingUse.Default) {
					if (parent.SoapBindingStyle == SoapBindingStyle.Document)
						Use = parent.LogicalType.BindingUse;
					else
						Use = SoapBindingUse.Literal;
				}
				
				Action = dma.Action;
				Binding = dma.Binding;
				RequestName = dma.RequestElementName;
				RequestNamespace = dma.RequestNamespace;
				ResponseName = dma.ResponseElementName;
				ResponseNamespace = dma.ResponseNamespace;
				ParameterStyle = dma.ParameterStyle;
				if (ParameterStyle == SoapParameterStyle.Default)
					ParameterStyle = parent.ParameterStyle;
				OneWay = dma.OneWay;
				SoapBindingStyle = SoapBindingStyle.Document;
			} else {
				SoapRpcMethodAttribute rma = (SoapRpcMethodAttribute) kind;
				Use = SoapBindingUse.Encoded;	// RPC always use encoded

				Action = rma.Action;
				if (Action != null && Action.Length == 0)
					Action = null;
				Binding = rma.Binding;
				
				// When using RPC, MS.NET seems to ignore RequestElementName and
				// MessageName, and it always uses the method name
				RequestName = source.Name;
				ResponseName = source.Name + "Response";
//				RequestName = rma.RequestElementName;
//				ResponseName = rma.ResponseElementName;
				RequestNamespace = rma.RequestNamespace;
				ResponseNamespace = rma.ResponseNamespace;
				ParameterStyle = SoapParameterStyle.Wrapped;
				OneWay = rma.OneWay;
				SoapBindingStyle = SoapBindingStyle.Rpc;

				// For RPC calls, make all arguments be part of the empty namespace
				optional_ns = new XmlElementAttribute ();
				optional_ns.Namespace = "";
			}

			if (OneWay){
				if (source.ReturnType != typeof (void))
					throw new Exception ("OneWay methods should not have a return value.");
				if (source.OutParameters.Length != 0)
					throw new Exception ("OneWay methods should not have out/ref parameters.");
			}
			
			BindingInfo binfo = parent.GetBinding (Binding);
			if (binfo == null) throw new InvalidOperationException ("Type '" + parent.Type + "' is missing WebServiceBinding attribute that defines a binding named '" + Binding + "'.");
			
			string serviceNamespace = binfo.Namespace;
				
			if (RequestNamespace == "") RequestNamespace = parent.LogicalType.GetWebServiceNamespace (serviceNamespace, Use);
			if (ResponseNamespace == "") ResponseNamespace = parent.LogicalType.GetWebServiceNamespace (serviceNamespace, Use);
			if (RequestName == "") RequestName = Name;
			if (ResponseName == "")	ResponseName = Name + "Response";
			if (Action == null)
				Action = serviceNamespace.EndsWith("/") ? (serviceNamespace + Name) : (serviceNamespace + "/" + Name);
			
			bool hasWrappingElem = (ParameterStyle == SoapParameterStyle.Wrapped);
			bool writeAccessors = (SoapBindingStyle == SoapBindingStyle.Rpc);
			
			XmlReflectionMember [] in_members = BuildRequestReflectionMembers (optional_ns);
			XmlReflectionMember [] out_members = BuildResponseReflectionMembers (optional_ns);

			if (Use == SoapBindingUse.Literal) {
				xmlImporter.IncludeTypes (source.CustomAttributeProvider);
				InputMembersMapping = xmlImporter.ImportMembersMapping (RequestName, RequestNamespace, in_members, hasWrappingElem);
				OutputMembersMapping = xmlImporter.ImportMembersMapping (ResponseName, ResponseNamespace, out_members, hasWrappingElem);
			}
			else {
				soapImporter.IncludeTypes (source.CustomAttributeProvider);
				InputMembersMapping = soapImporter.ImportMembersMapping (RequestName, RequestNamespace, in_members, hasWrappingElem, writeAccessors);
				OutputMembersMapping = soapImporter.ImportMembersMapping (ResponseName, ResponseNamespace, out_members, hasWrappingElem, writeAccessors);
			}

			InputMembersMapping.SetKey(RequestName);
			OutputMembersMapping.SetKey(ResponseName);

			requestSerializerId = parent.RegisterSerializer (InputMembersMapping);
			responseSerializerId = parent.RegisterSerializer (OutputMembersMapping);

			object[] o = source.GetCustomAttributes (typeof (SoapHeaderAttribute));
			ArrayList allHeaderList = new ArrayList (o.Length);
			ArrayList inHeaderList = new ArrayList (o.Length);
			ArrayList outHeaderList = new ArrayList (o.Length);
			ArrayList faultHeaderList = new ArrayList ();
			
			SoapHeaderDirection unknownHeaderDirections = (SoapHeaderDirection)0;
			
			for (int i = 0; i < o.Length; i++) {
				SoapHeaderAttribute att = (SoapHeaderAttribute) o[i];
				MemberInfo[] mems = source.DeclaringType.GetMember (att.MemberName);
				if (mems.Length == 0) throw new InvalidOperationException ("Member " + att.MemberName + " not found in class " + source.DeclaringType.FullName + ".");
				
				HeaderInfo header = new HeaderInfo (mems[0], att);
				allHeaderList.Add (header);
				if (!header.Custom) {
					if ((header.Direction & SoapHeaderDirection.In) != 0)
						inHeaderList.Add (header);
					if ((header.Direction & SoapHeaderDirection.Out) != 0)
						outHeaderList.Add (header);
					if ((header.Direction & SoapHeaderDirection.Fault) != 0)
						faultHeaderList.Add (header);
				} else
					unknownHeaderDirections |= header.Direction;
			}
			
			Headers = (HeaderInfo[]) allHeaderList.ToArray (typeof(HeaderInfo));

			if (inHeaderList.Count > 0 || (unknownHeaderDirections & SoapHeaderDirection.In) != 0) {
				InHeaders = (HeaderInfo[]) inHeaderList.ToArray (typeof(HeaderInfo));
				XmlReflectionMember[] members = BuildHeadersReflectionMembers (InHeaders);
				
				if (Use == SoapBindingUse.Literal)
					InputHeaderMembersMapping = xmlImporter.ImportMembersMapping ("", RequestNamespace, members, false);
				else
					InputHeaderMembersMapping = soapImporter.ImportMembersMapping ("", RequestNamespace, members, false, false);
				
				InputHeaderMembersMapping.SetKey(RequestName + ":InHeaders");
				
				requestHeadersSerializerId = parent.RegisterSerializer (InputHeaderMembersMapping);
			}
			
			if (outHeaderList.Count > 0 || (unknownHeaderDirections & SoapHeaderDirection.Out) != 0) {
				OutHeaders = (HeaderInfo[]) outHeaderList.ToArray (typeof(HeaderInfo));
				XmlReflectionMember[] members = BuildHeadersReflectionMembers (OutHeaders);
				
				if (Use == SoapBindingUse.Literal)
					OutputHeaderMembersMapping = xmlImporter.ImportMembersMapping ("", RequestNamespace, members, false);
				else
					OutputHeaderMembersMapping = soapImporter.ImportMembersMapping ("", RequestNamespace, members, false, false);

				OutputHeaderMembersMapping.SetKey(ResponseName + ":OutHeaders");

				responseHeadersSerializerId = parent.RegisterSerializer (OutputHeaderMembersMapping);
			}
			
			if (faultHeaderList.Count > 0 || (unknownHeaderDirections & SoapHeaderDirection.Fault) != 0) {
				FaultHeaders = (HeaderInfo[]) faultHeaderList.ToArray (typeof(HeaderInfo));
				XmlReflectionMember[] members = BuildHeadersReflectionMembers (FaultHeaders);
				
				if (Use == SoapBindingUse.Literal)
					FaultHeaderMembersMapping = xmlImporter.ImportMembersMapping ("", RequestNamespace, members, false);
				else
					FaultHeaderMembersMapping = soapImporter.ImportMembersMapping ("", RequestNamespace, members, false, false);
				
				faultHeadersSerializerId = parent.RegisterSerializer (FaultHeaderMembersMapping);
			}
			
			SoapExtensions = SoapExtension.GetMethodExtensions (source);
		}
Example #20
0
		public SoapTypeStubInfo (LogicalTypeInfo logicalTypeInfo)
		: base (logicalTypeInfo)
		{
			xmlImporter = new XmlReflectionImporter ();
			soapImporter = new SoapReflectionImporter ();
				
			if (typeof (SoapHttpClientProtocol).IsAssignableFrom (Type))
			{
				if (Bindings.Count == 0 || ((BindingInfo)Bindings[0]).WebServiceBindingAttribute == null)
					throw new InvalidOperationException ("WebServiceBindingAttribute is required on proxy class '" + Type + "'.");
				if (Bindings.Count > 1)
					throw new InvalidOperationException ("Only one WebServiceBinding attribute may be specified on type '" + Type + "'.");
			}

			object [] o = Type.GetCustomAttributes (typeof (SoapDocumentServiceAttribute), false);
			if (o.Length == 1){
				SoapDocumentServiceAttribute a = (SoapDocumentServiceAttribute) o [0];

				ParameterStyle = a.ParameterStyle;
				SoapBindingStyle = SoapBindingStyle.Document;
			} else {
				o = Type.GetCustomAttributes (typeof (SoapRpcServiceAttribute), false);
				if (o.Length == 1){
					ParameterStyle = SoapParameterStyle.Wrapped;
					SoapBindingStyle = SoapBindingStyle.Rpc;
				} else {
					ParameterStyle = SoapParameterStyle.Wrapped;
					SoapBindingStyle = SoapBindingStyle.Document;
				}
			}
			
			if (ParameterStyle == SoapParameterStyle.Default) ParameterStyle = SoapParameterStyle.Wrapped;
			
			xmlImporter.IncludeTypes (Type);
			soapImporter.IncludeTypes (Type);

#if MOBILE || XAMMAC_4_5
			SoapExtensions = new SoapExtensionRuntimeConfig [2][];
#else
			SoapExtensions = SoapExtension.GetTypeExtensions (Type);
#endif
		}
Example #21
0
		public SoapTypeStubInfo (LogicalTypeInfo logicalTypeInfo)
		: base (logicalTypeInfo)
		{
			xmlImporter = new XmlReflectionImporter ();
			soapImporter = new SoapReflectionImporter ();
			
			object [] o;

			o = Type.GetCustomAttributes (typeof (WebServiceBindingAttribute), false);
			
			if (typeof (SoapHttpClientProtocol).IsAssignableFrom (Type))
			{
				if (o.Length == 0)
					throw new InvalidOperationException ("WebServiceBindingAttribute is required on proxy class '" + Type + "'.");
				if (o.Length > 1)
					throw new InvalidOperationException ("Only one WebServiceBinding attribute may be specified on type '" + Type + "'.");
					
				// Remove the default binding, it is not needed since there is always
				// a binding attribute.
				Bindings.Clear ();
			}
				
			foreach (WebServiceBindingAttribute at in o)
				AddBinding (new BindingInfo (at, LogicalType.WebServiceNamespace));

			o = Type.GetCustomAttributes (typeof (SoapDocumentServiceAttribute), false);
			if (o.Length == 1){
				SoapDocumentServiceAttribute a = (SoapDocumentServiceAttribute) o [0];

				ParameterStyle = a.ParameterStyle;
				RoutingStyle = a.RoutingStyle;
				Use = a.Use;
				SoapBindingStyle = SoapBindingStyle.Document;
			} else {
				o = Type.GetCustomAttributes (typeof (SoapRpcServiceAttribute), false);
				if (o.Length == 1){
					SoapRpcServiceAttribute srs = (SoapRpcServiceAttribute) o [0];
					
					ParameterStyle = SoapParameterStyle.Wrapped;
					RoutingStyle = srs.RoutingStyle;
					Use = SoapBindingUse.Encoded;
					SoapBindingStyle = SoapBindingStyle.Rpc;
				} else {
					ParameterStyle = SoapParameterStyle.Wrapped;
					RoutingStyle = SoapServiceRoutingStyle.SoapAction;
					Use = SoapBindingUse.Literal;
					SoapBindingStyle = SoapBindingStyle.Document;
				}
			}
			
			if (ParameterStyle == SoapParameterStyle.Default) ParameterStyle = SoapParameterStyle.Wrapped;
			if (Use == SoapBindingUse.Default) Use = SoapBindingUse.Literal;
			
			xmlImporter.IncludeTypes (Type);
			soapImporter.IncludeTypes (Type);

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

			XmlTypeMapping tm;
			if (use == SoapBindingUse.Literal) {
				XmlReflectionImporter ri = new XmlReflectionImporter ();
				
				// MS.NET reflects header classes in a weird way. The root element
				// name is the CLR class name unless it is specified in an XmlRootAttribute.
				// The usual is to use the xml type name by default, but not in this case.
				
				XmlRootAttribute root;
				XmlAttributes ats = new XmlAttributes (type);
				if (ats.XmlRoot != null) root = ats.XmlRoot;
				else root = new XmlRootAttribute (type.Name);
				
				if (root.Namespace == null) root.Namespace = LogicalType.GetWebServiceLiteralNamespace (serviceNamespace);
				if (root.ElementName == null) root.ElementName = type.Name;
				
				tm = ri.ImportTypeMapping (type, root);
			}
			else {
				SoapReflectionImporter ri = new SoapReflectionImporter ();
				tm = ri.ImportTypeMapping (type, LogicalType.GetWebServiceEncodedNamespace (serviceNamespace));
			}
			
			int sid = RegisterSerializer (tm);

			serializers [type] = sid;
			header_serializers_byname [(int)use] [new XmlQualifiedName (tm.ElementName, tm.Namespace)] = sid;
		}