Exemple #1
0
        internal static void AnalyzeDescription(ServiceDescriptionCollection descriptions, BasicProfileViolationCollection violations)
        {
            bool flag = false;

            foreach (ServiceDescription description in descriptions)
            {
                SchemaCompiler.Compile(description.Types.Schemas);
                CheckWsdlImports(description, violations);
                CheckTypes(description, violations);
                foreach (string str in description.ValidationWarnings)
                {
                    violations.Add("R2028, R2029", str);
                }
                foreach (Binding binding in description.Bindings)
                {
                    flag |= AnalyzeBinding(binding, description, descriptions, violations);
                }
            }
            if (flag)
            {
                CheckExtensions(descriptions, violations);
            }
            else
            {
                violations.Add("Rxxxx");
            }
        }
Exemple #2
0
        private ServiceDescriptionImportWarnings Import(CodeNamespace codeNamespace, System.Xml.Serialization.ImportContext importContext, Hashtable exportContext, StringCollection warnings)
        {
            Hashtable hashtable2;

            this.allSchemas = new XmlSchemas();
            foreach (XmlSchema schema in this.schemas)
            {
                this.allSchemas.Add(schema);
            }
            foreach (ServiceDescription description in this.serviceDescriptions)
            {
                foreach (XmlSchema schema2 in description.Types.Schemas)
                {
                    this.allSchemas.Add(schema2);
                }
            }
            Hashtable references = new Hashtable();

            if (!this.allSchemas.Contains("http://schemas.xmlsoap.org/wsdl/"))
            {
                this.allSchemas.AddReference(ServiceDescription.Schema);
                references[ServiceDescription.Schema] = ServiceDescription.Schema;
            }
            if (!this.allSchemas.Contains("http://schemas.xmlsoap.org/soap/encoding/"))
            {
                this.allSchemas.AddReference(ServiceDescription.SoapEncodingSchema);
                references[ServiceDescription.SoapEncodingSchema] = ServiceDescription.SoapEncodingSchema;
            }
            this.allSchemas.Compile(null, false);
            foreach (ServiceDescription description2 in this.serviceDescriptions)
            {
                foreach (Message message in description2.Messages)
                {
                    foreach (MessagePart part in message.Parts)
                    {
                        bool flag;
                        bool flag2;
                        this.FindUse(part, out flag, out flag2);
                        if ((part.Element != null) && !part.Element.IsEmpty)
                        {
                            if (flag)
                            {
                                throw new InvalidOperationException(System.Web.Services.Res.GetString("CanTSpecifyElementOnEncodedMessagePartsPart", new object[] { part.Name, message.Name }));
                            }
                            XmlSchemaElement element = (XmlSchemaElement)this.allSchemas.Find(part.Element, typeof(XmlSchemaElement));
                            if (element != null)
                            {
                                AddSchema(element.Parent as XmlSchema, flag, flag2, this.abstractSchemas, this.concreteSchemas, references);
                                if ((element.SchemaTypeName != null) && !element.SchemaTypeName.IsEmpty)
                                {
                                    XmlSchemaType type = (XmlSchemaType)this.allSchemas.Find(element.SchemaTypeName, typeof(XmlSchemaType));
                                    if (type != null)
                                    {
                                        AddSchema(type.Parent as XmlSchema, flag, flag2, this.abstractSchemas, this.concreteSchemas, references);
                                    }
                                }
                            }
                        }
                        if ((part.Type != null) && !part.Type.IsEmpty)
                        {
                            XmlSchemaType type2 = (XmlSchemaType)this.allSchemas.Find(part.Type, typeof(XmlSchemaType));
                            if (type2 != null)
                            {
                                AddSchema(type2.Parent as XmlSchema, flag, flag2, this.abstractSchemas, this.concreteSchemas, references);
                            }
                        }
                    }
                }
            }
            foreach (XmlSchemas schemas in new XmlSchemas[] { this.abstractSchemas, this.concreteSchemas })
            {
                hashtable2 = new Hashtable();
                foreach (XmlSchema schema3 in schemas)
                {
                    this.AddImport(schema3, hashtable2);
                }
                foreach (XmlSchema schema4 in hashtable2.Keys)
                {
                    if ((references[schema4] == null) && !schemas.Contains(schema4))
                    {
                        schemas.Add(schema4);
                    }
                }
            }
            hashtable2 = new Hashtable();
            foreach (XmlSchema schema5 in this.allSchemas)
            {
                if (!this.abstractSchemas.Contains(schema5) && !this.concreteSchemas.Contains(schema5))
                {
                    this.AddImport(schema5, hashtable2);
                }
            }
            foreach (XmlSchema schema6 in hashtable2.Keys)
            {
                if (references[schema6] == null)
                {
                    if (!this.abstractSchemas.Contains(schema6))
                    {
                        this.abstractSchemas.Add(schema6);
                    }
                    if (!this.concreteSchemas.Contains(schema6))
                    {
                        this.concreteSchemas.Add(schema6);
                    }
                }
            }
            if (this.abstractSchemas.Count > 0)
            {
                foreach (XmlSchema schema7 in references.Values)
                {
                    this.abstractSchemas.AddReference(schema7);
                }
                foreach (string str in SchemaCompiler.Compile(this.abstractSchemas))
                {
                    warnings.Add(str);
                }
            }
            if (this.concreteSchemas.Count > 0)
            {
                foreach (XmlSchema schema8 in references.Values)
                {
                    this.concreteSchemas.AddReference(schema8);
                }
                foreach (string str2 in SchemaCompiler.Compile(this.concreteSchemas))
                {
                    warnings.Add(str2);
                }
            }
            if (this.ProtocolName.Length > 0)
            {
                ProtocolImporter importer = this.FindImporterByName(this.ProtocolName);
                if (importer.GenerateCode(codeNamespace, importContext, exportContext))
                {
                    return(importer.Warnings);
                }
            }
            else
            {
                for (int i = 0; i < this.importers.Length; i++)
                {
                    ProtocolImporter importer2 = this.importers[i];
                    if (importer2.GenerateCode(codeNamespace, importContext, exportContext))
                    {
                        return(importer2.Warnings);
                    }
                }
            }
            return(ServiceDescriptionImportWarnings.NoCodeGenerated);
        }
Exemple #3
0
        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);
        }