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; }
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; }
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; }
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 (); } } } }
static XmlTypeMapping CreateSoapMapping (Type type, SoapAttributeOverrides ao, string defaultNamespace) { SoapReflectionImporter importer = new SoapReflectionImporter (ao, defaultNamespace); return importer.ImportTypeMapping (type); }
static XmlTypeMapping CreateSoapMapping (Type type, SoapAttributeOverrides ao) { SoapReflectionImporter importer = new SoapReflectionImporter (ao); return importer.ImportTypeMapping (type); }
static XmlTypeMapping CreateSoapMapping (Type type) { SoapReflectionImporter importer = new SoapReflectionImporter (); return importer.ImportTypeMapping (type); }
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 (); }
[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"); }
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; }