internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, System.Xml.Serialization.ImportContext context) { if (!schemas.Contains("http://www.w3.org/2001/XMLSchema")) { schemas.AddReference(XmlSchemas.XsdSchema); schemas.SchemaSet.Add(XmlSchemas.XsdSchema); } if (!schemas.Contains("http://www.w3.org/XML/1998/namespace")) { schemas.AddReference(XmlSchemas.XmlSchema); schemas.SchemaSet.Add(XmlSchemas.XmlSchema); } this.schemas = schemas; this.options = options; this.codeProvider = codeProvider; this.context = context; this.Schemas.SetCache(this.Context.Cache, this.Context.ShareTypes); SchemaImporterExtensionsSection section = System.Configuration.PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SchemaImporterExtensionsSectionPath) as SchemaImporterExtensionsSection; if (section != null) { this.extensions = section.SchemaImporterExtensionsInternal; } else { this.extensions = new SchemaImporterExtensionCollection(); } }
internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, ImportContext context) { if (!schemas.Contains(XmlSchema.Namespace)) { schemas.AddReference(XmlSchemas.XsdSchema); schemas.SchemaSet.Add(XmlSchemas.XsdSchema); } if (!schemas.Contains(XmlReservedNs.NsXml)) { schemas.AddReference(XmlSchemas.XmlSchema); schemas.SchemaSet.Add(XmlSchemas.XmlSchema); } this.schemas = schemas; this.options = options; this.codeProvider = codeProvider; this.context = context; Schemas.SetCache(Context.Cache, Context.ShareTypes); SchemaImporterExtensionsSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SchemaImporterExtensionsSectionPath) as SchemaImporterExtensionsSection; if (section != null) { extensions = section.SchemaImporterExtensionsInternal; } else { extensions = new SchemaImporterExtensionCollection(); } }
internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, ImportContext context) { if (!schemas.Contains(XmlSchema.Namespace)) { schemas.AddReference(XmlSchemas.XsdSchema); schemas.SchemaSet.Add(XmlSchemas.XsdSchema); } if (!schemas.Contains(XmlReservedNs.NsXml)) { schemas.AddReference(XmlSchemas.XmlSchema); schemas.SchemaSet.Add(XmlSchemas.XmlSchema); } _schemas = schemas; _options = options; _context = context; Schemas.SetCache(Context.Cache, Context.ShareTypes); }
internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, ImportContext context) { if (!schemas.Contains(XmlSchema.Namespace)) { schemas.AddReference(XmlSchemas.XsdSchema); schemas.SchemaSet.Add(XmlSchemas.XsdSchema); } if (!schemas.Contains(XmlReservedNs.NsXml)) { schemas.AddReference(XmlSchemas.XmlSchema); schemas.SchemaSet.Add(XmlSchemas.XmlSchema); } this.schemas = schemas; this.options = options; this.codeProvider = codeProvider; this.context = context; Schemas.SetCache(Context.Cache, Context.ShareTypes); SchemaImporterExtensionsSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SchemaImporterExtensionsSectionPath) as SchemaImporterExtensionsSection; if (section != null) extensions = section.SchemaImporterExtensionsInternal; else extensions = new SchemaImporterExtensionCollection(); }
private static void AddSchema(XmlSchema schema, bool isEncoded, bool isLiteral, XmlSchemas abstractSchemas, XmlSchemas concreteSchemas, Hashtable references) { if (schema != null) { if (isEncoded && !abstractSchemas.Contains(schema)) { if (references.Contains(schema)) { abstractSchemas.AddReference(schema); } else { abstractSchemas.Add(schema); } } if (isLiteral && !concreteSchemas.Contains(schema)) { if (references.Contains(schema)) { concreteSchemas.AddReference(schema); } else { concreteSchemas.Add(schema); } } } }
// Segregate the schemas containing abstract types from those // containing regular XML definitions. This is important because // when you import something returning the ur-type (object), then // you need to import ALL types/elements within ALL schemas. We // don't want the RPC-based types leaking over into the XML-based // element definitions or literal types in the encoded schemas, // beacase it can cause schema coimpilation falure. static void CollectEncodedAndLiteralSchemas(WsdlNS.ServiceDescriptionCollection serviceDescriptions, XmlSchemas encodedSchemas, XmlSchemas literalSchemas, XmlSchemaSet allSchemas) { XmlSchema wsdl = StockSchemas.CreateWsdl(); XmlSchema soap = StockSchemas.CreateSoap(); XmlSchema soapEncoding = StockSchemas.CreateSoapEncoding(); Hashtable references = new Hashtable(); if (!allSchemas.Contains(wsdl.TargetNamespace)) { references[soap] = wsdl; } if (!allSchemas.Contains(soap.TargetNamespace)) { references[soap] = soap; } if (!allSchemas.Contains(soapEncoding.TargetNamespace)) { references[soapEncoding] = soapEncoding; } foreach (WsdlNS.ServiceDescription description in serviceDescriptions) { foreach (WsdlNS.Message message in description.Messages) { foreach (WsdlNS.MessagePart part in message.Parts) { bool isEncoded; bool isLiteral; FindUse(part, out isEncoded, out isLiteral); if (part.Element != null && !part.Element.IsEmpty) { XmlSchemaElement element = FindSchemaElement(allSchemas, part.Element); if (element != null) { AddSchema(element.Parent as XmlSchema, isEncoded, isLiteral, encodedSchemas, literalSchemas, references); if (element.SchemaTypeName != null && !element.SchemaTypeName.IsEmpty) { XmlSchemaType type = FindSchemaType(allSchemas, element.SchemaTypeName); if (type != null) { AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, encodedSchemas, literalSchemas, references); } } } } if (part.Type != null && !part.Type.IsEmpty) { XmlSchemaType type = FindSchemaType(allSchemas, part.Type); if (type != null) { AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, encodedSchemas, literalSchemas, references); } } } } } Hashtable imports; foreach (XmlSchemas schemas in new XmlSchemas[] { encodedSchemas, literalSchemas }) { // collect all imports imports = new Hashtable(); foreach (XmlSchema schema in schemas) { AddImport(schema, imports, allSchemas); } // make sure we add them to the corresponding schema collections foreach (XmlSchema schema in imports.Keys) { if (references[schema] == null && !schemas.Contains(schema)) { schemas.Add(schema); } } } // If a schema was not referenced by either a literal or an encoded message part, // add it to both collections. There's no way to tell which it should be. imports = new Hashtable(); foreach (XmlSchema schema in allSchemas.Schemas()) { if (!encodedSchemas.Contains(schema) && !literalSchemas.Contains(schema)) { AddImport(schema, imports, allSchemas); } } // make sure we add them to the corresponding schema collections foreach (XmlSchema schema in imports.Keys) { if (references[schema] != null) continue; if (!encodedSchemas.Contains(schema)) { encodedSchemas.Add(schema); } if (!literalSchemas.Contains(schema)) { literalSchemas.Add(schema); } } if (encodedSchemas.Count > 0) { foreach (XmlSchema schema in references.Values) { encodedSchemas.AddReference(schema); } } if (literalSchemas.Count > 0) { foreach (XmlSchema schema in references.Values) { literalSchemas.AddReference(schema); } } AddSoapEncodingSchemaIfNeeded(literalSchemas); }
static void AddSchema(XmlSchema schema, bool isEncoded, bool isLiteral, XmlSchemas encodedSchemas, XmlSchemas literalSchemas, Hashtable references) { if (schema != null) { if (isEncoded && !encodedSchemas.Contains(schema)) { if (references.Contains(schema)) { encodedSchemas.AddReference(schema); } else { encodedSchemas.Add(schema); } } if (isLiteral && !literalSchemas.Contains(schema)) { if (references.Contains(schema)) { literalSchemas.AddReference(schema); } else { literalSchemas.Add(schema); } } } }
private ServiceDescriptionImportWarnings Import(CodeNamespace codeNamespace, ImportContext importContext, Hashtable exportContext, StringCollection warnings) { allSchemas = new XmlSchemas(); foreach (XmlSchema schema in schemas) { allSchemas.Add(schema); } foreach (ServiceDescription description in serviceDescriptions) { foreach (XmlSchema schema in description.Types.Schemas) { allSchemas.Add(schema); } } Hashtable references = new Hashtable(); if (!allSchemas.Contains(ServiceDescription.Namespace)) { allSchemas.AddReference(ServiceDescription.Schema); references[ServiceDescription.Schema] = ServiceDescription.Schema; } if (!allSchemas.Contains(Soap.Encoding)) { allSchemas.AddReference(ServiceDescription.SoapEncodingSchema); references[ServiceDescription.SoapEncodingSchema] = ServiceDescription.SoapEncodingSchema; } allSchemas.Compile(null, false); // Segregate the schemas containing abstract types from those // containing regular XML definitions. This is important because // when you import something returning the ur-type (object), then // you need to import ALL types/elements within ALL schemas. We // don't want the RPC-based types leaking over into the XML-based // element definitions. This also occurs when you have derivation: // we need to search the schemas for derived types: but WHICH schemas // should we search. foreach (ServiceDescription description in serviceDescriptions) { foreach (Message message in description.Messages) { foreach (MessagePart part in message.Parts) { bool isEncoded; bool isLiteral; FindUse(part, out isEncoded, out isLiteral); if (part.Element != null && !part.Element.IsEmpty) { if (isEncoded) throw new InvalidOperationException(Res.GetString(Res.CanTSpecifyElementOnEncodedMessagePartsPart, part.Name, message.Name)); XmlSchemaElement element = (XmlSchemaElement)allSchemas.Find(part.Element, typeof(XmlSchemaElement)); if (element != null) { AddSchema(element.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references); if (element.SchemaTypeName != null && !element.SchemaTypeName.IsEmpty) { XmlSchemaType type = (XmlSchemaType)allSchemas.Find(element.SchemaTypeName, typeof(XmlSchemaType)); if (type != null) { AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references); } } } } if (part.Type != null && !part.Type.IsEmpty) { XmlSchemaType type = (XmlSchemaType)allSchemas.Find(part.Type, typeof(XmlSchemaType)); if (type != null) { AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references); } } } } } Hashtable imports; foreach (XmlSchemas xmlschemas in new XmlSchemas[] { abstractSchemas, concreteSchemas }) { // collect all imports imports = new Hashtable(); foreach (XmlSchema schema in xmlschemas) { AddImport(schema, imports); } // make sure we add them to the corresponding schema collections foreach (XmlSchema schema in imports.Keys) { if (references[schema] == null && !xmlschemas.Contains(schema)) { xmlschemas.Add(schema); } } } // If a schema was not referenced by either a literal or an encoded message part, // add it to both collections. There's no way to tell which it should be. imports = new Hashtable(); foreach (XmlSchema schema in allSchemas) { if (!abstractSchemas.Contains(schema) && !concreteSchemas.Contains(schema)) { AddImport(schema, imports); } } // make sure we add them to the corresponding schema collections foreach (XmlSchema schema in imports.Keys) { if (references[schema] != null) continue; if (!abstractSchemas.Contains(schema)) { abstractSchemas.Add(schema); } if (!concreteSchemas.Contains(schema)) { concreteSchemas.Add(schema); } } if (abstractSchemas.Count > 0) { foreach (XmlSchema schema in references.Values) { abstractSchemas.AddReference(schema); } StringCollection schemaWarnings = SchemaCompiler.Compile(abstractSchemas); foreach (string warning in schemaWarnings) warnings.Add(warning); } if (concreteSchemas.Count > 0) { foreach (XmlSchema schema in references.Values) { concreteSchemas.AddReference(schema); } StringCollection schemaWarnings = SchemaCompiler.Compile(concreteSchemas); foreach (string warning in schemaWarnings) warnings.Add(warning); } if (ProtocolName.Length > 0) { // If a protocol was specified, only try that one ProtocolImporter importer = FindImporterByName(ProtocolName); if (importer.GenerateCode(codeNamespace, importContext, exportContext)) return importer.Warnings; } else { // Otherwise, do "best" protocol (first one that generates something) for (int i = 0; i < importers.Length; i++) { ProtocolImporter importer = importers[i]; if (importer.GenerateCode(codeNamespace, importContext, exportContext)) { return importer.Warnings; } } } return ServiceDescriptionImportWarnings.NoCodeGenerated; }