private void GetProperties(XmlSchema xmlSchema, string elementname) { foreach (object xItem in xmlSchema.SchemaTypes.Values) { XmlSchemaComplexType item = xItem as XmlSchemaComplexType; #region item if (item != null) { if (item.Name.Equals(elementname)) { XmlSchemaContentModel model = item.ContentModel; XmlSchemaComplexContent complex = model as XmlSchemaComplexContent; SoapClasses newClass = this.GetClass(elementname); if (complex != null && newClass != null) { XmlSchemaComplexContentExtension extension = complex.Content as XmlSchemaComplexContentExtension; XmlSchemaParticle particle = extension.Particle; XmlSchemaSequence sequence = particle as XmlSchemaSequence; if (extension != null) { newClass.SuperClassType = extension.BaseTypeName.Name; } if (sequence != null) { foreach (XmlSchemaElement childElement in sequence.Items) { if (newClass != null) { SoapClassProperties newProp = new SoapClassProperties(XpoDefault.Session); newProp.Name = childElement.Name; newProp.PropertyClassType = childElement.SchemaTypeName.Name; newProp.IsArray = childElement.SchemaTypeName.Name.StartsWith("ArrayOf");//.Equals("unbounded")); newClass.Properties.Add(newProp); } } } newClass.Save(); } return; } } #endregion } }
protected virtual void Visit(XmlSchemaContentModel model) { XmlSchemaSimpleContent simpleContent; XmlSchemaComplexContent complexContent; if (Casting.TryCast(model, out simpleContent)) { Visit(simpleContent); } else if (Casting.TryCast(model, out complexContent)) { Visit(complexContent); } else { throw ExceptionBuilder.UnexpectedSchemaObjectType(model); } }
private ArrayMapping ImportArrayMapping(XmlSchemaType type, string ns) { ArrayMapping arrayMapping; if (type.Name == Soap.Array && ns == Soap.Encoding) { arrayMapping = new ArrayMapping(); TypeMapping mapping = GetRootMapping(); ElementAccessor itemAccessor = new ElementAccessor(); itemAccessor.IsSoap = true; itemAccessor.Name = Soap.UrType; itemAccessor.Namespace = ns; itemAccessor.Mapping = mapping; itemAccessor.IsNullable = true; itemAccessor.Form = XmlSchemaForm.None; arrayMapping.Elements = new ElementAccessor[] { itemAccessor }; arrayMapping.TypeDesc = itemAccessor.Mapping.TypeDesc.CreateArrayTypeDesc(); arrayMapping.TypeName = "ArrayOf" + CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeName); return(arrayMapping); } if (!(type.DerivedFrom.Name == Soap.Array && type.DerivedFrom.Namespace == Soap.Encoding)) { return(null); } // the type should be a XmlSchemaComplexType XmlSchemaContentModel model = ((XmlSchemaComplexType)type).ContentModel; // the Content should be an restriction if (!(model.Content is XmlSchemaComplexContentRestriction)) { return(null); } arrayMapping = new ArrayMapping(); XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)model.Content; for (int i = 0; i < restriction.Attributes.Count; i++) { XmlSchemaAttribute attribute = restriction.Attributes[i] as XmlSchemaAttribute; if (attribute != null && attribute.RefName.Name == Soap.ArrayType && attribute.RefName.Namespace == Soap.Encoding) { // read the value of the wsdl:arrayType attribute string arrayType = null; if (attribute.UnhandledAttributes != null) { foreach (XmlAttribute a in attribute.UnhandledAttributes) { if (a.LocalName == Wsdl.ArrayType && a.NamespaceURI == Wsdl.Namespace) { arrayType = a.Value; break; } } } if (arrayType != null) { string dims; XmlQualifiedName typeName = TypeScope.ParseWsdlArrayType(arrayType, out dims, attribute); TypeMapping mapping; TypeDesc td = Scope.GetTypeDesc(typeName.Name, typeName.Namespace); if (td != null && td.IsPrimitive) { mapping = new PrimitiveMapping(); mapping.TypeDesc = td; mapping.TypeName = td.DataType.Name; } else { mapping = ImportType(typeName, false); } ElementAccessor itemAccessor = new ElementAccessor(); itemAccessor.IsSoap = true; itemAccessor.Name = typeName.Name; itemAccessor.Namespace = ns; itemAccessor.Mapping = mapping; itemAccessor.IsNullable = true; itemAccessor.Form = XmlSchemaForm.None; arrayMapping.Elements = new ElementAccessor[] { itemAccessor }; arrayMapping.TypeDesc = itemAccessor.Mapping.TypeDesc.CreateArrayTypeDesc(); arrayMapping.TypeName = "ArrayOf" + CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeName); return(arrayMapping); } } } XmlSchemaParticle particle = restriction.Particle; if (particle is XmlSchemaAll || particle is XmlSchemaSequence) { XmlSchemaGroupBase group = (XmlSchemaGroupBase)particle; if (group.Items.Count != 1 || !(group.Items[0] is XmlSchemaElement)) { return(null); } XmlSchemaElement itemElement = (XmlSchemaElement)group.Items[0]; if (!itemElement.IsMultipleOccurrence) { return(null); } ElementAccessor itemAccessor = ImportElement(itemElement, ns); arrayMapping.Elements = new ElementAccessor[] { itemAccessor }; arrayMapping.TypeDesc = ((TypeMapping)itemAccessor.Mapping).TypeDesc.CreateArrayTypeDesc(); } else { return(null); } return(arrayMapping); }
private ArrayMapping ImportArrayMapping(XmlSchemaType type, string ns) { ArrayMapping mapping; if ((type.Name == "Array") && (ns == "http://schemas.xmlsoap.org/soap/encoding/")) { mapping = new ArrayMapping(); TypeMapping rootMapping = base.GetRootMapping(); ElementAccessor accessor = new ElementAccessor { IsSoap = true, Name = "anyType", Namespace = ns, Mapping = rootMapping, IsNullable = true, Form = XmlSchemaForm.None }; mapping.Elements = new ElementAccessor[] { accessor }; mapping.TypeDesc = accessor.Mapping.TypeDesc.CreateArrayTypeDesc(); mapping.TypeName = "ArrayOf" + CodeIdentifier.MakePascal(accessor.Mapping.TypeName); return(mapping); } if ((type.DerivedFrom.Name != "Array") || (type.DerivedFrom.Namespace != "http://schemas.xmlsoap.org/soap/encoding/")) { return(null); } XmlSchemaContentModel contentModel = ((XmlSchemaComplexType)type).ContentModel; if (!(contentModel.Content is XmlSchemaComplexContentRestriction)) { return(null); } mapping = new ArrayMapping(); XmlSchemaComplexContentRestriction content = (XmlSchemaComplexContentRestriction)contentModel.Content; for (int i = 0; i < content.Attributes.Count; i++) { XmlSchemaAttribute parent = content.Attributes[i] as XmlSchemaAttribute; if (((parent != null) && (parent.RefName.Name == "arrayType")) && (parent.RefName.Namespace == "http://schemas.xmlsoap.org/soap/encoding/")) { string str = null; if (parent.UnhandledAttributes != null) { foreach (XmlAttribute attribute2 in parent.UnhandledAttributes) { if ((attribute2.LocalName == "arrayType") && (attribute2.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/")) { str = attribute2.Value; break; } } } if (str != null) { string str2; TypeMapping mapping3; XmlQualifiedName name = TypeScope.ParseWsdlArrayType(str, out str2, parent); TypeDesc typeDesc = base.Scope.GetTypeDesc(name.Name, name.Namespace); if ((typeDesc != null) && typeDesc.IsPrimitive) { mapping3 = new PrimitiveMapping { TypeDesc = typeDesc, TypeName = typeDesc.DataType.Name }; } else { mapping3 = this.ImportType(name, false); } ElementAccessor accessor2 = new ElementAccessor { IsSoap = true, Name = name.Name, Namespace = ns, Mapping = mapping3, IsNullable = true, Form = XmlSchemaForm.None }; mapping.Elements = new ElementAccessor[] { accessor2 }; mapping.TypeDesc = accessor2.Mapping.TypeDesc.CreateArrayTypeDesc(); mapping.TypeName = "ArrayOf" + CodeIdentifier.MakePascal(accessor2.Mapping.TypeName); return(mapping); } } } XmlSchemaParticle particle = content.Particle; if (!(particle is XmlSchemaAll) && !(particle is XmlSchemaSequence)) { return(null); } XmlSchemaGroupBase base2 = (XmlSchemaGroupBase)particle; if ((base2.Items.Count != 1) || !(base2.Items[0] is XmlSchemaElement)) { return(null); } XmlSchemaElement element = (XmlSchemaElement)base2.Items[0]; if (!element.IsMultipleOccurrence) { return(null); } ElementAccessor accessor3 = this.ImportElement(element, ns); mapping.Elements = new ElementAccessor[] { accessor3 }; mapping.TypeDesc = accessor3.Mapping.TypeDesc.CreateArrayTypeDesc(); return(mapping); }
public void Parse() { UriBuilder uriBuilder = new UriBuilder(webserv.Url); uriBuilder.Query = "WSDL"; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uriBuilder.Uri); webRequest.ContentType = "text/xml;charset=\"utf-8\""; webRequest.Method = "GET"; webRequest.Accept = "text/xml"; ServiceDescription serviceDescription; using (WebResponse response = webRequest.GetResponse()) { using (Stream stream = response.GetResponseStream()) { serviceDescription = ServiceDescription.Read(stream); } } var oldfuncs = (from q in new XPQuery <WebFunctions>(XpoDefault.Session) where q.Service.Oid == webserv.Oid select q).ToList(); if (serviceDescription != null && serviceDescription.Services.Count > 0) { ServiceDescriptionImporter importer = new ServiceDescriptionImporter(); importer.ProtocolName = "Soap11"; importer.AddServiceDescription(serviceDescription, null, null); importer.Style = ServiceDescriptionImportStyle.Client; importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties; Service service = serviceDescription.Services[0]; this.Namespace = serviceDescription.TargetNamespace; this.ServiceName = service.Name; webserv.ServiceName = service.Name; webserv.NameSpace = serviceDescription.TargetNamespace; webserv.UpdateDate = DateTime.Now; for (int i = webserv.SoapClasses.Count - 1; i >= 0; i--) { webserv.SoapClasses[i].Delete(); } #region Operation List <string> operationNames = new List <string>(); //Loop through the port types in the service description and list all of the //web service's operations and each operations input/output PortType portType = serviceDescription.PortTypes[0]; //foreach (PortType portType in serviceDescription.PortTypes) { int FunctionIndex = 0; this.Functions = new List <WebFunctions>(); foreach (Operation operation in portType.Operations) { WebFunctions newFunc = new WebFunctions(); newFunc.Service = webserv; var oldfunc = oldfuncs.Where(x => x.Name == operation.Name).FirstOrDefault(); if (oldfunc != null) { newFunc.Output = oldfunc.Output; } newFunc.Name = operation.Name; newFunc.SoapAction = this.Namespace + operation.Name; operationNames.Add(operation.Name); foreach (var message in operation.Messages) { if (message is OperationInput) { foreach (Message messagePart in serviceDescription.Messages) { if (messagePart.Name != ((OperationMessage)message).Message.Name) { continue; } foreach (MessagePart part in messagePart.Parts) { newFunc.InputType = part.Element.Name; } } } if (message is OperationOutput) { foreach (Message messagePart in serviceDescription.Messages) { if (messagePart.Name != ((OperationMessage)message).Message.Name) { continue; } foreach (MessagePart part in messagePart.Parts) { newFunc.OutputType = part.Element.Name; } } } } newFunc.Save(); this.Functions.Add(newFunc); FunctionIndex++; } } //End listing of types for (int i = oldfuncs.Count - 1; i >= 0; i--) { oldfuncs[i].Delete(); } #endregion #region Types Types types = serviceDescription.Types; XmlSchema xmlSchema = types.Schemas[0]; foreach (object item in xmlSchema.Items) { XmlSchemaComplexType _complexType = item as System.Xml.Schema.XmlSchemaComplexType; XmlSchemaElement schemaElement = item as XmlSchemaElement; XmlSchemaComplexType complexType = item as XmlSchemaComplexType; if (schemaElement != null && JavaTypeConverter.IsComplexType(schemaElement.Name)) { SoapClasses newClass = this.GetClass(schemaElement.Name); newClass.Name = schemaElement.Name; newClass.Service = webserv; newClass.Type = ClassType.Unknown; newClass.SuperClassType = string.Empty; newClass.Output = false; if (_complexType != null) { XmlSchemaContentModel model = _complexType.ContentModel; XmlSchemaComplexContent complex = model as XmlSchemaComplexContent; if (complex != null) { XmlSchemaComplexContentExtension extension = complex.Content as XmlSchemaComplexContentExtension; if (extension != null) { newClass.SuperClassType = extension.BaseTypeName.Name; } } } XmlSchemaType schemaType = schemaElement.SchemaType; XmlSchemaComplexType schemaComplexType = schemaType as XmlSchemaComplexType; if (schemaComplexType != null) { XmlSchemaParticle particle = schemaComplexType.Particle; XmlSchemaSequence sequence = particle as XmlSchemaSequence; if (sequence != null) { foreach (XmlSchemaElement childElement in sequence.Items) { SoapClassProperties newProp = new SoapClassProperties(XpoDefault.Session); newProp.Name = childElement.Name; newProp.PropertyClassType = childElement.SchemaTypeName.Name; newProp.IsArray = childElement.SchemaTypeName.Name.StartsWith("ArrayOf"); newClass.Properties.Add(newProp); } } } newClass.Save(); //this.ComplexTypes.Add(newClass); } else if (complexType != null) { OutputElements(complexType.Particle, complexType.Name); if (complexType.Particle == null) { GetProperties(xmlSchema, complexType.Name); } } } #region enums foreach (object xItem in xmlSchema.SchemaTypes.Values) { XmlSchemaSimpleType item2 = xItem as XmlSchemaSimpleType; if (item2 != null) { GetEnum(xmlSchema, item2.Name); } } #endregion #endregion } webserv.Save(); }
static void ContentHandler(XmlSchemaObject schemaObject, HelpExampleGeneratorContext context) { XmlSchemaContentModel model = (XmlSchemaContentModel)schemaObject; InvokeHandler(model.Content, context); }
private void IterateOverElement(string root, XmlSchemaElement element) { var complexType = element.SchemaType as XmlSchemaComplexType; if (complexType == null) { return; } if (complexType.AttributeUses.Count > 0) { IDictionaryEnumerator enumerator = complexType.AttributeUses.GetEnumerator(); while (enumerator.MoveNext()) { var attribute = (XmlSchemaAttribute)enumerator.Value; Console.WriteLine(root + @"." + attribute.Name + @" (attribute)"); } } XmlSchemaContentModel contentModel = complexType.ContentModel; if (contentModel == null) { return; } XmlSchemaContent content = contentModel.Content; if (content is XmlSchemaComplexContentExtension) { var ext = (XmlSchemaComplexContentExtension)content; XmlQualifiedName baseTypeField = ext.BaseTypeName; _baseSignalName = baseTypeField.Name; _baseSignalNameSpace = baseTypeField.Namespace; //Need to get the base target namespace foreach (XmlSchemaObject o in ext.Attributes) { var attribute = (XmlSchemaAttribute)o; XmlSchemaAnnotation annotation = attribute.Annotation; XmlSchemaType schemaType = attribute.SchemaType; String defaultValue = attribute.DefaultValue; String fixedValue = attribute.FixedValue; String name = attribute.Name; var signalAttribute = new SignalAttribute(name); signalAttribute.DefaultValue = defaultValue; signalAttribute.FixedValue = fixedValue; signalAttribute.SchemaType = attribute.SchemaTypeName.Name; _attributes.Add(signalAttribute); //Add AttributeRestrictions here if (schemaType is XmlSchemaSimpleType) { var simpleType = (XmlSchemaSimpleType)schemaType; XmlSchemaSimpleTypeContent simpleContent = simpleType.Content; foreach (XmlAttribute ua in simpleContent.UnhandledAttributes) { //if( "minInclusive".Equals( ua.LocalName ) // restriction = new RangeRestriction( //Console.WriteLine("\t\t\t\t" + ua.Name + "\t\t" + ua.Value); var restriction = new AttributeRestriction(ua); signalAttribute.AddRestriction(restriction); } } } } }