Example #1
0
 private object GenerateMembersElement(XmlMembersMapping xmlMapping)
 {
     // #10675: we should implement this method. WCF is the major customer of the method
     // as WCF uses XmlReflectionImporter.ImportMembersMapping and generates special
     // serializers for OperationContracts.
     throw new NotImplementedException();
 }
Example #2
0
        /// <include file='doc\XmlCodeExporter.uex' path='docs/doc[@for="XmlCodeExporter.ExportMembersMapping"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
        {
            xmlMembersMapping.CheckShallow();
            CheckScope(xmlMembersMapping.Scope);

            for (int i = 0; i < xmlMembersMapping.Count; i++)
            {
                AccessorMapping mapping = xmlMembersMapping[i].Mapping;
                if (mapping.Xmlns == null)
                {
                    if (mapping.Attribute != null)
                    {
                        ExportType(mapping.Attribute.Mapping, Accessor.UnescapeName(mapping.Attribute.Name), mapping.Attribute.Namespace, null, false);
                    }
                    if (mapping.Elements != null)
                    {
                        for (int j = 0; j < mapping.Elements.Length; j++)
                        {
                            ElementAccessor element = mapping.Elements[j];
                            ExportType(element.Mapping, Accessor.UnescapeName(element.Name), element.Namespace, null, false);
                        }
                    }
                    if (mapping.Text != null)
                    {
                        ExportType(mapping.Text.Mapping, Accessor.UnescapeName(mapping.Text.Name), mapping.Text.Namespace, null, false);
                    }
                }
            }
        }
 private void CreateEncodedMessage(Message message, MessageBinding messageBinding, XmlMembersMapping members, bool wrapped)
 {
     this.SoapExporter.ExportMembersMapping(members, wrapped);
     if (wrapped)
     {
         MessagePart messagePart = new MessagePart {
             Name = "parameters",
             Type = new XmlQualifiedName(members.TypeName, members.TypeNamespace)
         };
         message.Parts.Add(messagePart);
     }
     else
     {
         for (int i = 0; i < members.Count; i++)
         {
             XmlMemberMapping mapping = members[i];
             MessagePart part2 = new MessagePart {
                 Name = mapping.XsdElementName,
                 Type = new XmlQualifiedName(mapping.TypeName, mapping.TypeNamespace)
             };
             message.Parts.Add(part2);
         }
     }
     messageBinding.Extensions.Add(this.CreateSoapBodyBinding(SoapBindingUse.Encoded, members.Namespace));
 }
        protected virtual void WriteMessage(XmlMembersMapping membersMap, object[] parameters)
        {
            if (membersMap.HasWrapperElement)
            {
                TopLevelElement();
                WriteStartElement(membersMap.ElementName, membersMap.Namespace, (_format == SerializationFormat.Encoded));

                if (Writer.LookupPrefix(XmlSchema.Namespace) == null)
                {
                    WriteAttribute("xmlns", "xsd", XmlSchema.Namespace, XmlSchema.Namespace);
                }

                if (Writer.LookupPrefix(XmlSchema.InstanceNamespace) == null)
                {
                    WriteAttribute("xmlns", "xsi", XmlSchema.InstanceNamespace, XmlSchema.InstanceNamespace);
                }
            }

            WriteMembers((ClassMap)membersMap.ObjectMap, parameters, true);

            if (membersMap.HasWrapperElement)
            {
                WriteEndElement();
            }
        }
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
 {
     xmlMembersMapping.CheckShallow();
     base.CheckScope(xmlMembersMapping.Scope);
     for (int i = 0; i < xmlMembersMapping.Count; i++)
     {
         AccessorMapping mapping = xmlMembersMapping[i].Mapping;
         if (mapping.Xmlns == null)
         {
             if (mapping.Attribute != null)
             {
                 this.ExportType(mapping.Attribute.Mapping, Accessor.UnescapeName(mapping.Attribute.Name), mapping.Attribute.Namespace, null, false);
             }
             if (mapping.Elements != null)
             {
                 for (int j = 0; j < mapping.Elements.Length; j++)
                 {
                     ElementAccessor accessor = mapping.Elements[j];
                     this.ExportType(accessor.Mapping, Accessor.UnescapeName(accessor.Name), accessor.Namespace, null, false);
                 }
             }
             if (mapping.Text != null)
             {
                 this.ExportType(mapping.Text.Mapping, Accessor.UnescapeName(mapping.Text.Name), mapping.Text.Namespace, null, false);
             }
         }
     }
 }
Example #6
0
 /// <include file='doc\XmlSchemaExporter.uex' path='docs/doc[@for="XmlSchemaExporter.ExportMembersMapping1"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping, bool exportEnclosingType) {
     xmlMembersMapping.CheckShallow();
     MembersMapping mapping = (MembersMapping)xmlMembersMapping.Accessor.Mapping;
     CheckScope(xmlMembersMapping.Scope);
     if (mapping.HasWrapperElement && exportEnclosingType) {
         ExportElement(xmlMembersMapping.Accessor);
     }
     else {
         foreach (MemberMapping member in mapping.Members) {
             if (member.Attribute != null) 
                 throw new InvalidOperationException(Res.GetString(Res.XmlBareAttributeMember, member.Attribute.Name));
             else if (member.Text != null) 
                 throw new InvalidOperationException(Res.GetString(Res.XmlBareTextMember, member.Text.Name));
             else if (member.Elements == null || member.Elements.Length == 0)
                 continue;
             
             if (member.TypeDesc.IsArrayLike && !(member.Elements[0].Mapping is ArrayMapping)) 
                 throw new InvalidOperationException(Res.GetString(Res.XmlIllegalArrayElement, member.Elements[0].Name));
             
             if (exportEnclosingType) {
                 ExportElement(member.Elements[0]);
             }
             else {
                 ExportMapping(member.Elements[0].Mapping, member.Elements[0].Namespace, member.Elements[0].Any);
             }
         }
     }
     ExportRootIfNecessary(xmlMembersMapping.Scope);
 }
Example #7
0
 /// <include file='doc\SoapCodeExporter.uex' path='docs/doc[@for="SoapCodeExporter.ExportMembersMapping"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping) {
     CheckScope(xmlMembersMapping.Scope);
     CheckNamespace();
     for (int i = 0; i < xmlMembersMapping.Count; i++) {
         ExportElement((ElementAccessor)xmlMembersMapping[i].Accessor);
     }
 }
Example #8
0
 protected virtual object ReadMessage(XmlMembersMapping typeMap)
 {
     object[] array = new object[typeMap.Count];
     if (typeMap.HasWrapperElement)
     {
         ArrayList allMembers = ((ClassMap)typeMap.ObjectMap).AllMembers;
         for (int i = 0; i < allMembers.Count; i++)
         {
             XmlTypeMapMember xmlTypeMapMember = (XmlTypeMapMember)allMembers[i];
             if (!xmlTypeMapMember.IsReturnValue && xmlTypeMapMember.TypeData.IsValueType)
             {
                 this.SetMemberValueFromAttr(xmlTypeMapMember, array, this.CreateInstance(xmlTypeMapMember.TypeData.Type), true);
             }
         }
         if (this._format == SerializationFormat.Encoded)
         {
             while (base.Reader.NodeType == XmlNodeType.Element)
             {
                 string attribute = base.Reader.GetAttribute("root", "http://schemas.xmlsoap.org/soap/encoding/");
                 if (attribute == null || XmlConvert.ToBoolean(attribute))
                 {
                     break;
                 }
                 base.ReadReferencedElement();
                 base.Reader.MoveToContent();
             }
         }
         while (base.Reader.NodeType != XmlNodeType.EndElement && base.Reader.ReadState == ReadState.Interactive)
         {
             if (base.Reader.IsStartElement(typeMap.ElementName, typeMap.Namespace) || this._format == SerializationFormat.Encoded)
             {
                 this.ReadAttributeMembers((ClassMap)typeMap.ObjectMap, array, true);
                 if (!base.Reader.IsEmptyElement)
                 {
                     base.Reader.ReadStartElement();
                     this.ReadMembers((ClassMap)typeMap.ObjectMap, array, true, false);
                     base.ReadEndElement();
                     break;
                 }
                 base.Reader.Skip();
                 base.Reader.MoveToContent();
             }
             else
             {
                 base.UnknownNode(null);
                 base.Reader.MoveToContent();
             }
         }
     }
     else
     {
         this.ReadMembers((ClassMap)typeMap.ObjectMap, array, true, this._format == SerializationFormat.Encoded);
     }
     if (this._format == SerializationFormat.Encoded)
     {
         base.ReadReferencedElements();
     }
     return(array);
 }
 internal void Add(MessagePartDescription part, XmlMemberMapping memberMapping, XmlMembersMapping membersMapping, bool isEncoded)
 {
     PartInfo partInfo = new PartInfo();
     partInfo.MemberMapping = memberMapping;
     partInfo.MembersMapping = membersMapping;
     partInfo.IsEncoded = isEncoded;
     partInfoTable[part] = partInfo;
 }
 /// <include file='doc\SoapCodeExporter.uex' path='docs/doc[@for="SoapCodeExporter.ExportMembersMapping"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
 {
     xmlMembersMapping.CheckShallow();
     CheckScope(xmlMembersMapping.Scope);
     for (int i = 0; i < xmlMembersMapping.Count; i++)
     {
         ExportElement((ElementAccessor)xmlMembersMapping[i].Accessor);
     }
 }
        internal SoapParameters(XmlMembersMapping request, XmlMembersMapping response, string[] parameterOrder, CodeIdentifiers identifiers) {
            ArrayList requestList = new ArrayList();
            ArrayList responseList = new ArrayList();

            AddMappings(requestList, request);
            if (response != null) AddMappings(responseList, response);

            if (parameterOrder != null) {
                for (int i = 0; i < parameterOrder.Length; i++) {
                    string elementName = parameterOrder[i];
                    XmlMemberMapping requestMapping = FindMapping(requestList, elementName);
                    SoapParameter parameter = new SoapParameter();
                    if (requestMapping != null) {
                        if (RemoveByRefMapping(responseList, requestMapping))
                            parameter.codeFlags = CodeFlags.IsByRef;
                        parameter.mapping = requestMapping;
                        requestList.Remove(requestMapping);
                        AddParameter(parameter);
                    }
                    else {
                        XmlMemberMapping responseMapping = FindMapping(responseList, elementName);
                        if (responseMapping != null) {
                            parameter.codeFlags = CodeFlags.IsOut;
                            parameter.mapping = responseMapping;
                            responseList.Remove(responseMapping);
                            AddParameter(parameter);
                        }
                    }
                }
            }

            foreach (XmlMemberMapping requestMapping in requestList) {
                SoapParameter parameter = new SoapParameter();
                if (RemoveByRefMapping(responseList, requestMapping))
                    parameter.codeFlags = CodeFlags.IsByRef;
                parameter.mapping = requestMapping;
                AddParameter(parameter);
            }

            if (responseList.Count > 0) {
                if (!((XmlMemberMapping) responseList[0]).CheckSpecified) {
                    ret = (XmlMemberMapping)responseList[0];
                    responseList.RemoveAt(0);
                }
                foreach (XmlMemberMapping responseMapping in responseList) {
                    SoapParameter parameter = new SoapParameter();
                    parameter.mapping = responseMapping;
                    parameter.codeFlags = CodeFlags.IsOut;
                    AddParameter(parameter);
                }
            }

            foreach (SoapParameter parameter in parameters) {
                parameter.name = identifiers.MakeUnique(CodeIdentifier.MakeValid(parameter.mapping.MemberName));
            }
        }
Example #12
0
        /// <include file='doc\XmlCodeExporter.uex' path='docs/doc[@for="XmlCodeExporter.ExportMembersMapping"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping) {
            CheckScope(xmlMembersMapping.Scope);
            CheckNamespace();

            for (int i = 0; i < xmlMembersMapping.Count; i++) {
                Accessor accessor = xmlMembersMapping[i].Accessor;
                if (!(accessor is XmlnsAccessor)) {
                    ExportType(accessor.Mapping, Accessor.UnescapeName(accessor.Name), accessor.Namespace, null);
                }
            }
        }
Example #13
0
        protected virtual object ReadMessage(XmlMembersMapping typeMap)
        {
            object[] parameters = new object[typeMap.Count];

            if (typeMap.HasWrapperElement)
            {
                if (_format == SerializationFormat.Encoded)
                {
                    while (Reader.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        string root = Reader.GetAttribute("root", XmlSerializer.EncodingNamespace);
                        if (root == null || System.Xml.XmlConvert.ToBoolean(root))
                        {
                            break;
                        }
                        ReadReferencedElement();
                        Reader.MoveToContent();
                    }
                }

                while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
                {
                    if (Reader.IsStartElement(typeMap.ElementName, typeMap.Namespace) ||
                        _format == SerializationFormat.Encoded)
                    {
                        if (Reader.IsEmptyElement)
                        {
                            Reader.Skip(); Reader.MoveToContent(); continue;
                        }
                        Reader.ReadStartElement();
                        ReadMembers((ClassMap)typeMap.ObjectMap, parameters, true, false);
                        ReadEndElement();
                        break;
                    }
                    else
                    {
                        UnknownNode(null);
                    }

                    Reader.MoveToContent();
                }
            }
            else
            {
                ReadMembers((ClassMap)typeMap.ObjectMap, parameters, true, _format == SerializationFormat.Encoded);
            }

            if (_format == SerializationFormat.Encoded)
            {
                ReadReferencedElements();
            }

            return(parameters);
        }
Example #14
0
 /// <include file='doc\SoapSchemaExporter.uex' path='docs/doc[@for="SoapSchemaExporter.ExportMembersMapping1"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping, bool exportEnclosingType) {
     CheckScope(xmlMembersMapping.Scope);
     MembersMapping membersMapping = (MembersMapping)xmlMembersMapping.Accessor.Mapping;
     if (exportEnclosingType) {
         ExportTypeMapping(membersMapping, null);
     }
     else {
         foreach (MemberMapping memberMapping in membersMapping.Members) {
             if (memberMapping.Elements.Length > 0) 
                 ExportTypeMapping(memberMapping.Elements[0].Mapping, null);
         }
     }
 }
Example #15
0
        /// <include file='doc\XmlCodeExporter.uex' path='docs/doc[@for="XmlCodeExporter.ExportMembersMapping"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
        {
            CheckScope(xmlMembersMapping.Scope);
            CheckNamespace();

            for (int i = 0; i < xmlMembersMapping.Count; i++)
            {
                Accessor accessor = xmlMembersMapping[i].Accessor;
                if (!(accessor is XmlnsAccessor))
                {
                    ExportType(accessor.Mapping, Accessor.UnescapeName(accessor.Name), accessor.Namespace, null);
                }
            }
        }
Example #16
0
        public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate)
        {
            XmlMemberMapping[] mapping = new XmlMemberMapping[members.Length];
            for (int n = 0; n < members.Length; n++)
            {
                XmlTypeMapMember mapMem = CreateMapMember(members[n], ns);
                mapping[n] = new XmlMemberMapping(members[n].MemberName, ns, mapMem, true);
            }
            XmlMembersMapping mps = new XmlMembersMapping(elementName, ns, hasWrapperElement, writeAccessors, mapping);

            mps.RelatedMaps = relatedMaps;
            mps.Format      = SerializationFormat.Encoded;
            mps.Source      = new MembersSerializationSource(elementName, hasWrapperElement, members, writeAccessors, false, null, includedTypes);
            return(mps);
        }
Example #17
0
        /// <include file='doc\XmlSchemaExporter.uex' path='docs/doc[@for="XmlSchemaExporter.ExportTypeMapping1"]/*' />
        public XmlQualifiedName ExportTypeMapping(XmlMembersMapping xmlMembersMapping)
        {
            CheckScope(xmlMembersMapping.Scope);
            MembersMapping mapping = (MembersMapping)xmlMembersMapping.Accessor.Mapping;

            if (mapping.Members.Length == 1 && mapping.Members[0].Elements[0].Mapping is SpecialMapping)
            {
                SpecialMapping special = (SpecialMapping)mapping.Members[0].Elements[0].Mapping;
                XmlSchemaType  type    = ExportSpecialMapping(special, xmlMembersMapping.Accessor.Namespace, false);
                type.Name = xmlMembersMapping.Accessor.Name;
                AddSchemaItem(type, xmlMembersMapping.Accessor.Namespace, null);
                ExportRootIfNecessary(xmlMembersMapping.Scope);
                return(new XmlQualifiedName(xmlMembersMapping.Accessor.Name, xmlMembersMapping.Accessor.Namespace));
            }
            return(null);
        }
Example #18
0
        /// <include file='doc\SoapReflectionImporter.uex' path='docs/doc[@for="SoapReflectionImporter.ImportMembersMapping2"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate)
        {
            ElementAccessor element = new ElementAccessor();

            element.IsSoap = true;
            element.Name   = Accessor.EscapeName(elementName, false);

            element.Mapping          = ImportMembersMapping(members, ns, hasWrapperElement, writeAccessors, validate);
            element.Mapping.TypeName = elementName;
            element.Namespace        = element.Mapping.Namespace == null ? ns : element.Mapping.Namespace;
            element.Form             = XmlSchemaForm.Qualified;
            XmlMembersMapping xmlMapping = new XmlMembersMapping(typeScope, element);

            xmlMapping.GenerateSerializer = true;
            return(xmlMapping);
        }
Example #19
0
 /// <include file='doc\XmlSchemaExporter.uex' path='docs/doc[@for="XmlSchemaExporter.ExportTypeMapping1"]/*' />
 public XmlQualifiedName ExportTypeMapping(XmlMembersMapping xmlMembersMapping) {
     xmlMembersMapping.CheckShallow();
     CheckScope(xmlMembersMapping.Scope);
     MembersMapping mapping = (MembersMapping)xmlMembersMapping.Accessor.Mapping;
     if (mapping.Members.Length == 1 && mapping.Members[0].Elements[0].Mapping is SpecialMapping) {
         SpecialMapping special = (SpecialMapping)mapping.Members[0].Elements[0].Mapping;
         XmlSchemaType type = ExportSpecialMapping(special, xmlMembersMapping.Accessor.Namespace, false, null);
         if (type != null && type.Name != null && type.Name.Length > 0) {
             type.Name = xmlMembersMapping.Accessor.Name;
             AddSchemaItem(type, xmlMembersMapping.Accessor.Namespace, null);
         }
         ExportRootIfNecessary(xmlMembersMapping.Scope);
         return (new XmlQualifiedName(xmlMembersMapping.Accessor.Name, xmlMembersMapping.Accessor.Namespace));
     }
     return null;
 }
        XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate, XmlMappingAccess access)
        {
            elementName = XmlConvert.EncodeLocalName(elementName);
            XmlMemberMapping[] mapping = new XmlMemberMapping[members.Length];
            for (int n = 0; n < members.Length; n++)
            {
                XmlTypeMapMember mapMem = CreateMapMember(members[n], ns);
                mapping[n] = new XmlMemberMapping(XmlConvert.EncodeLocalName(members[n].MemberName), ns, mapMem, true);
            }
            XmlMembersMapping mps = new XmlMembersMapping(elementName, ns, hasWrapperElement, writeAccessors, mapping);

            mps.RelatedMaps = relatedMaps;
            mps.Format      = SerializationFormat.Encoded;
            Type[] extraTypes = includedTypes != null ? (Type[])includedTypes.ToArray(typeof(Type)) : null;
            mps.Source = new MembersSerializationSource(elementName, hasWrapperElement, members, writeAccessors, false, null, extraTypes);
            return(mps);
        }
Example #21
0
        public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate, XmlMappingAccess access)
        {
            elementName = XmlConvert.EncodeLocalName(elementName);
            XmlMemberMapping[] array = new XmlMemberMapping[members.Length];
            for (int i = 0; i < members.Length; i++)
            {
                XmlTypeMapMember mapMem = this.CreateMapMember(members[i], ns);
                array[i] = new XmlMemberMapping(XmlConvert.EncodeLocalName(members[i].MemberName), ns, mapMem, true);
            }
            XmlMembersMapping xmlMembersMapping = new XmlMembersMapping(elementName, ns, hasWrapperElement, writeAccessors, array);

            xmlMembersMapping.RelatedMaps = this.relatedMaps;
            xmlMembersMapping.Format      = SerializationFormat.Encoded;
            Type[] array2 = (this.includedTypes == null) ? null : ((Type[])this.includedTypes.ToArray(typeof(Type)));
            xmlMembersMapping.Source = new MembersSerializationSource(elementName, hasWrapperElement, members, writeAccessors, false, null, array2);
            return(xmlMembersMapping);
        }
Example #22
0
        /// <include file='doc\SoapReflectionImporter.uex' path='docs/doc[@for="SoapReflectionImporter.ImportMembersMapping3"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate, XmlMappingAccess access)
        {
            ElementAccessor element = new ElementAccessor();

            element.IsSoap = true;
            element.Name   = elementName == null || elementName.Length == 0 ? elementName : XmlConvert.EncodeLocalName(elementName);

            element.Mapping          = ImportMembersMapping(members, ns, hasWrapperElement, writeAccessors, validate, new RecursionLimiter());
            element.Mapping.TypeName = elementName;
            element.Namespace        = element.Mapping.Namespace == null ? ns : element.Mapping.Namespace;
            element.Form             = XmlSchemaForm.Qualified;
            XmlMembersMapping xmlMapping = new XmlMembersMapping(_typeScope, element, access);

            xmlMapping.IsSoap             = true;
            xmlMapping.GenerateSerializer = true;
            return(xmlMapping);
        }
        /// <include file='doc\SoapSchemaExporter.uex' path='docs/doc[@for="SoapSchemaExporter.ExportMembersMapping1"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping, bool exportEnclosingType)
        {
            CheckScope(xmlMembersMapping.Scope);
            MembersMapping membersMapping = (MembersMapping)xmlMembersMapping.Accessor.Mapping;

            if (exportEnclosingType)
            {
                ExportTypeMapping(membersMapping, null);
            }
            else
            {
                foreach (MemberMapping memberMapping in membersMapping.Members)
                {
                    if (memberMapping.Elements.Length > 0)
                    {
                        ExportTypeMapping(memberMapping.Elements[0].Mapping, null);
                    }
                }
            }
        }
Example #24
0
 protected virtual void WriteMessage(XmlMembersMapping membersMap, object[] parameters)
 {
     if (membersMap.HasWrapperElement)
     {
         base.TopLevelElement();
         base.WriteStartElement(membersMap.ElementName, membersMap.Namespace, this._format == SerializationFormat.Encoded);
         if (base.Writer.LookupPrefix("http://www.w3.org/2001/XMLSchema") == null)
         {
             base.WriteAttribute("xmlns", "xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/2001/XMLSchema");
         }
         if (base.Writer.LookupPrefix("http://www.w3.org/2001/XMLSchema-instance") == null)
         {
             base.WriteAttribute("xmlns", "xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/2001/XMLSchema-instance");
         }
     }
     this.WriteMembers((ClassMap)membersMap.ObjectMap, parameters, true);
     if (membersMap.HasWrapperElement)
     {
         base.WriteEndElement();
     }
 }
Example #25
0
        public XmlMembersMapping ImportMembersMapping(string elementName,
                                                      string ns,
                                                      XmlReflectionMember [] members,
                                                      bool hasWrapperElement)
        {
//			Reset ();	Disabled. See ChangeLog

            XmlMemberMapping[] mapping = new XmlMemberMapping[members.Length];
            for (int n = 0; n < members.Length; n++)
            {
                XmlTypeMapMember mapMem = CreateMapMember(members[n], ns);
                mapping[n] = new XmlMemberMapping(members[n].MemberName, ns, mapMem, false);
            }
            XmlMembersMapping mps = new XmlMembersMapping(elementName, ns, hasWrapperElement, false, mapping);

            mps.RelatedMaps = relatedMaps;
            mps.Format      = SerializationFormat.Literal;
            mps.Source      = new MembersSerializationSource(elementName, hasWrapperElement, members, false, true, ns, includedTypes);
            if (allowPrivateTypes)
            {
                mps.Source.CanBeGenerated = false;
            }
            return(mps);
        }
Example #26
0
        /// <include file='doc\XmlSchemaExporter.uex' path='docs/doc[@for="XmlSchemaExporter.ExportMembersMapping"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
        {
            MembersMapping mapping = (MembersMapping)xmlMembersMapping.Accessor.Mapping;

            CheckScope(xmlMembersMapping.Scope);
            if (mapping.HasWrapperElement)
            {
                ExportElement(xmlMembersMapping.Accessor);
            }
            else
            {
                foreach (MemberMapping member in mapping.Members)
                {
                    if (member.Attribute != null)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.XmlBareAttributeMember, member.Attribute.Name));
                    }
                    else if (member.Text != null)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.XmlBareTextMember, member.Text.Name));
                    }
                    else if (member.Elements == null || member.Elements.Length == 0)
                    {
                        continue;
                    }

                    if (member.TypeDesc.IsArray && !(member.Elements[0].Mapping is ArrayMapping))
                    {
                        throw new InvalidOperationException(Res.GetString(Res.XmlIllegalArrayElement, member.Elements[0].Name));
                    }

                    ExportElement(member.Elements[0]);
                }
            }
            ExportRootIfNecessary(xmlMembersMapping.Scope);
        }
Example #27
0
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
 {
     ExportMembersMapping(xmlMembersMapping, true);
 }
        protected virtual object ReadMessage(XmlMembersMapping typeMap)
        {
            object[] parameters = new object[typeMap.Count];

            if (typeMap.HasWrapperElement)
            {
                // bug #79988: out parameters need to be initialized if they
                // are value types
                ArrayList members = ((ClassMap)typeMap.ObjectMap).AllMembers;
                for (int n = 0; n < members.Count; n++)
                {
                    XmlTypeMapMember mem = (XmlTypeMapMember)members [n];
                    if (!mem.IsReturnValue && mem.TypeData.IsValueType)
                    {
                        SetMemberValueFromAttr(mem, parameters, CreateInstance(
                                                   mem.TypeData.Type), true);
                    }
                }

                if (_format == SerializationFormat.Encoded)
                {
                    while (Reader.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        string root = Reader.GetAttribute("root", XmlSerializer.EncodingNamespace);
                        if (root == null || System.Xml.XmlConvert.ToBoolean(root))
                        {
                            break;
                        }
                        ReadReferencedElement();
                        Reader.MoveToContent();
                    }
                }

                while (Reader.NodeType != System.Xml.XmlNodeType.EndElement &&
                       // it could be an empty root element
                       Reader.ReadState == ReadState.Interactive)
                {
                    if (Reader.IsStartElement(typeMap.ElementName, typeMap.Namespace) ||
                        _format == SerializationFormat.Encoded)
                    {
                        ReadAttributeMembers((ClassMap)typeMap.ObjectMap, parameters, true);
                        if (Reader.IsEmptyElement)
                        {
                            Reader.Skip();
                            Reader.MoveToContent();
                            continue;
                        }
                        Reader.ReadStartElement();
                        ReadMembers((ClassMap)typeMap.ObjectMap, parameters, true, false);
                        ReadEndElement();
                        break;
                    }
                    else
                    {
                        UnknownNode(null);
                    }

                    Reader.MoveToContent();
                }
            }
            else
            {
                ReadMembers((ClassMap)typeMap.ObjectMap, parameters, true, _format == SerializationFormat.Encoded);
            }

            if (_format == SerializationFormat.Encoded)
            {
                ReadReferencedElements();
            }

            return(parameters);
        }
        string GenerateLiteralMembersElement(XmlMembersMapping xmlMembersMapping) {
            ElementAccessor element = xmlMembersMapping.Accessor;
            MemberMapping[] mappings = ((MembersMapping)element.Mapping).Members;
            bool hasWrapperElement = ((MembersMapping)element.Mapping).HasWrapperElement;
            string methodName = NextMethodName(element.Name);
            Writer.WriteLine();
            Writer.Write("public object[] ");
            Writer.Write(methodName);
            Writer.WriteLine("() {");
            Writer.Indent++;
            Writer.WriteLine("Reader.MoveToContent();");

            Writer.Write("object[] p = new object[");
            Writer.Write(mappings.Length.ToString(CultureInfo.InvariantCulture));
            Writer.WriteLine("];");
            InitializeValueTypes("p", mappings);

            int wrapperLoopIndex = 0;
            if (hasWrapperElement) {
                wrapperLoopIndex = WriteWhileNotLoopStart();
                Writer.Indent++;
                WriteIsStartTag(element.Name, element.Form == XmlSchemaForm.Qualified ? element.Namespace : "");
            }

            Member anyText = null;
            Member anyElement = null;
            Member anyAttribute = null; 

            ArrayList membersList = new ArrayList();
            ArrayList textOrArrayMembersList = new ArrayList();
            ArrayList attributeMembersList = new ArrayList();
            
            for (int i = 0; i < mappings.Length; i++) {
                MemberMapping mapping = mappings[i];
                string source = "p[" + i.ToString(CultureInfo.InvariantCulture) + "]";
                string arraySource = source;
                if (mapping.Xmlns != null) {
                    arraySource = "((" + mapping.TypeDesc.CSharpName + ")" + source + ")";
                }
                string choiceSource = GetChoiceIdentifierSource(mappings, mapping);
                Member member = new Member(this, source, arraySource, "a", i, mapping, choiceSource);
                Member anyMember = new Member(this, source, null, "a", i, mapping, choiceSource);
                if (!mapping.IsSequence)
                    member.ParamsReadSource = "paramsRead[" + i.ToString(CultureInfo.InvariantCulture) + "]";
                if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) {
                    string nameSpecified = mapping.Name + "Specified";
                    for (int j = 0; j < mappings.Length; j++) {
                        if (mappings[j].Name == nameSpecified) {
                            member.CheckSpecifiedSource = "p[" + j.ToString(CultureInfo.InvariantCulture) + "]";
                            break;
                        }
                    }
                }
                bool foundAnyElement = false;
                if (mapping.Text != null) anyText = anyMember;
                if (mapping.Attribute != null && mapping.Attribute.Any)
                    anyAttribute = anyMember;
                if (mapping.Attribute != null || mapping.Xmlns != null)
                    attributeMembersList.Add(member);
                else if (mapping.Text != null)
                    textOrArrayMembersList.Add(member);

                if (!mapping.IsSequence) {
                    for (int j = 0; j < mapping.Elements.Length; j++) {
                        if (mapping.Elements[j].Any && mapping.Elements[j].Name.Length == 0) {
                            anyElement = anyMember;
                            if (mapping.Attribute == null && mapping.Text == null)
                                textOrArrayMembersList.Add(anyMember);
                            foundAnyElement = true;
                            break;
                        }
                    }
                }
                if (mapping.Attribute != null || mapping.Text != null || foundAnyElement)
                    membersList.Add(anyMember);
                else if (mapping.TypeDesc.IsArrayLike && !(mapping.Elements.Length == 1 && mapping.Elements[0].Mapping is ArrayMapping)) {
                    membersList.Add(anyMember);
                    textOrArrayMembersList.Add(anyMember);
                }
                else {
                    if (mapping.TypeDesc.IsArrayLike && !mapping.TypeDesc.IsArray)
                        member.ParamsReadSource = null; // collection
                    membersList.Add(member);
                }
            }
            Member[] members = (Member[]) membersList.ToArray(typeof(Member));
            Member[] textOrArrayMembers = (Member[]) textOrArrayMembersList.ToArray(typeof(Member));

            if (members.Length > 0 && members[0].Mapping.IsReturnValue) Writer.WriteLine("IsReturnValue = true;");
            
            WriteParamsRead(mappings.Length);

            if (attributeMembersList.Count > 0) {
                Member[] attributeMembers = (Member[]) attributeMembersList.ToArray(typeof(Member));
                WriteMemberBegin(attributeMembers);
                WriteAttributes(attributeMembers, anyAttribute, "UnknownNode", "(object)p");
                WriteMemberEnd(attributeMembers);
                Writer.WriteLine("Reader.MoveToElement();");
            }

            WriteMemberBegin(textOrArrayMembers);

            if (hasWrapperElement) {
                Writer.WriteLine("if (Reader.IsEmptyElement) { Reader.Skip(); Reader.MoveToContent(); continue; }");
                Writer.WriteLine("Reader.ReadStartElement();");
            }
            if (IsSequence(members)) {
                Writer.WriteLine("int state = 0;");
            }
            int loopIndex = WriteWhileNotLoopStart();
            Writer.Indent++;

            string unknownNode = "UnknownNode((object)p, " + ExpectedElements(members) + ");";
            WriteMemberElements(members, unknownNode, unknownNode, anyElement, anyText, null);

            Writer.WriteLine("Reader.MoveToContent();");
            WriteWhileLoopEnd(loopIndex);

            WriteMemberEnd(textOrArrayMembers);

            if (hasWrapperElement) {
                Writer.WriteLine("ReadEndElement();");

                Writer.Indent--;
                Writer.WriteLine("}");

                WriteUnknownNode("UnknownNode", "null", element, true);

                Writer.WriteLine("Reader.MoveToContent();");
                WriteWhileLoopEnd(wrapperLoopIndex);
            }
            
            Writer.WriteLine("return p;");
            Writer.Indent--;
            Writer.WriteLine("}");
            
            return methodName;
        }
        void CreateHeaderMessages(string methodName, SoapBindingUse use, XmlMembersMapping inHeaderMappings, XmlMembersMapping outHeaderMappings, SoapReflectedHeader[] headers, bool rpc) {
            // 
            if (use == SoapBindingUse.Encoded) {
                SoapExporter.ExportMembersMapping(inHeaderMappings, false);
                if (outHeaderMappings != null)
                    SoapExporter.ExportMembersMapping(outHeaderMappings, false);
            }
            else {
                SchemaExporter.ExportMembersMapping(inHeaderMappings);
                if (outHeaderMappings != null)
                    SchemaExporter.ExportMembersMapping(outHeaderMappings);
            }

            CodeIdentifiers identifiers = new CodeIdentifiers();
            int inCount = 0, outCount = 0;
            for (int i = 0; i < headers.Length; i++) {
                SoapReflectedHeader soapHeader = headers[i];
                if (!soapHeader.custom) continue;
                
                XmlMemberMapping member;
                if ((soapHeader.direction & SoapHeaderDirection.In) != 0) {
                    member = inHeaderMappings[inCount++];
                    if (soapHeader.direction != SoapHeaderDirection.In)
                        outCount++;
                }
                else {
                    member = outHeaderMappings[outCount++];
                }

                MessagePart part = new MessagePart();
                part.Name = member.XsdElementName;
                if (use == SoapBindingUse.Encoded)
                    part.Type = new XmlQualifiedName(member.TypeName, member.TypeNamespace);
                else
                    part.Element = new XmlQualifiedName(member.XsdElementName, member.Namespace);
                Message message = new Message();
                message.Name = identifiers.AddUnique(methodName + part.Name, message);
                message.Parts.Add(part);
                HeaderMessages.Add(message);

                ServiceDescriptionFormatExtension soapHeaderBinding = CreateSoapHeaderBinding(new XmlQualifiedName(message.Name, Binding.ServiceDescription.TargetNamespace), part.Name, rpc ? member.Namespace : null, use);
                
                if ((soapHeader.direction & SoapHeaderDirection.In) != 0)
                    OperationBinding.Input.Extensions.Add(soapHeaderBinding);
                if ((soapHeader.direction & SoapHeaderDirection.Out) != 0)
                    OperationBinding.Output.Extensions.Add(soapHeaderBinding);

                if ((soapHeader.direction & SoapHeaderDirection.Fault) != 0) {
                    if (soapMethod.IsClaimsConformance) {
                        throw new InvalidOperationException(Res.GetString(Res.BPConformanceHeaderFault, soapMethod.methodInfo.ToString(), soapMethod.methodInfo.DeclaringType.FullName, "Direction", typeof(SoapHeaderDirection).Name, SoapHeaderDirection.Fault.ToString())); 
                    }
                    OperationBinding.Output.Extensions.Add(soapHeaderBinding);
                }
            }
        }
        void CreateMessage(bool rpc, SoapBindingUse use, SoapParameterStyle paramStyle, Message message, MessageBinding messageBinding, XmlMembersMapping members) {
            bool wrapped = paramStyle != SoapParameterStyle.Bare;

            if (use == SoapBindingUse.Encoded)
                CreateEncodedMessage(message, messageBinding, members, wrapped && !rpc);
            else
                CreateLiteralMessage(message, messageBinding, members, wrapped && !rpc, rpc);
        }
		CodeMemberMethod GenerateMethod (CodeIdentifiers memberIds, HttpOperationBinding httpOper, XmlMembersMapping inputMembers, XmlTypeMapping outputMember)
		{
			CodeIdentifiers pids = new CodeIdentifiers ();
			CodeMemberMethod method = new CodeMemberMethod ();
			CodeMemberMethod methodBegin = new CodeMemberMethod ();
			CodeMemberMethod methodEnd = new CodeMemberMethod ();
			method.Attributes = MemberAttributes.Public;
			methodBegin.Attributes = MemberAttributes.Public;
			methodEnd.Attributes = MemberAttributes.Public;
			
			// Find unique names for temporary variables
			
			for (int n=0; n<inputMembers.Count; n++)
				pids.AddUnique (inputMembers[n].MemberName, inputMembers[n]);

			string varAsyncResult = pids.AddUnique ("asyncResult","asyncResult");
			string varCallback = pids.AddUnique ("callback","callback");
			string varAsyncState = pids.AddUnique ("asyncState","asyncState");

			string messageName = memberIds.AddUnique(CodeIdentifier.MakeValid(Operation.Name),method);

			method.Name = Operation.Name;
			methodBegin.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("Begin" + Operation.Name),method);
			methodEnd.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + Operation.Name),method);

			method.ReturnType = new CodeTypeReference (typeof(void));
			methodEnd.ReturnType = new CodeTypeReference (typeof(void));
			methodEnd.Parameters.Add (new CodeParameterDeclarationExpression (typeof (IAsyncResult),varAsyncResult));

			CodeExpression[] paramArray = new CodeExpression [inputMembers.Count];

			for (int n=0; n<inputMembers.Count; n++)
			{
				string ptype = GetSimpleType (inputMembers[n]);
				CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (ptype, inputMembers[n].MemberName);
				
				param.Direction = FieldDirection.In;
				method.Parameters.Add (param);
				methodBegin.Parameters.Add (param);
				paramArray [n] = new CodeVariableReferenceExpression (param.Name);
			}

			bool isVoid = true;
			if (outputMember != null)
			{
				method.ReturnType = new CodeTypeReference (outputMember.TypeFullName);
				methodEnd.ReturnType = new CodeTypeReference (outputMember.TypeFullName);
				xmlExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, outputMember, "");
				isVoid = false;
			}

			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (AsyncCallback),varCallback));
			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (object),varAsyncState));
			methodBegin.ReturnType = new CodeTypeReference (typeof(IAsyncResult));

			// Array of input parameters
			
			CodeArrayCreateExpression methodParams;
			if (paramArray.Length > 0)
				methodParams = new CodeArrayCreateExpression (typeof(object), paramArray);
			else
				methodParams = new CodeArrayCreateExpression (typeof(object), 0);

			// Generate method url
			
			CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();
			
			CodeExpression thisURlExp = new CodeFieldReferenceExpression (ethis, "Url");
			CodePrimitiveExpression metUrl = new CodePrimitiveExpression (httpOper.Location);
			CodeBinaryOperatorExpression expMethodLocation = new CodeBinaryOperatorExpression (thisURlExp, CodeBinaryOperatorType.Add, metUrl);
			
			// Invoke call
			
			CodePrimitiveExpression varMsgName = new CodePrimitiveExpression (messageName);
			CodeMethodInvokeExpression inv;

			inv = new CodeMethodInvokeExpression (ethis, "Invoke", varMsgName, expMethodLocation, methodParams);
			if (!isVoid)
				method.Statements.Add (new CodeMethodReturnStatement (new CodeCastExpression (method.ReturnType, inv)));
			else
				method.Statements.Add (inv);
			
			// Begin Invoke Call
			
			CodeExpression expCallb = new CodeVariableReferenceExpression (varCallback);
			CodeExpression expAsyncs = new CodeVariableReferenceExpression (varAsyncState);
			inv = new CodeMethodInvokeExpression (ethis, "BeginInvoke", varMsgName, expMethodLocation, methodParams, expCallb, expAsyncs);
			methodBegin.Statements.Add (new CodeMethodReturnStatement (inv));
			
			// End Invoke call
			
			CodeExpression varAsyncr = new CodeVariableReferenceExpression (varAsyncResult);
			inv = new CodeMethodInvokeExpression (ethis, "EndInvoke", varAsyncr);
			if (!isVoid)
				methodEnd.Statements.Add (new CodeMethodReturnStatement (new CodeCastExpression (methodEnd.ReturnType, inv)));
			else
				methodEnd.Statements.Add (inv);
			
			// Attributes

			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.HttpMethodAttribute");
			att.Arguments.Add (new CodeAttributeArgument (new CodeTypeOfExpression(GetOutMimeFormatter ())));
			att.Arguments.Add (new CodeAttributeArgument (new CodeTypeOfExpression(GetInMimeFormatter ())));
			AddCustomAttribute (method, att, true);
		
			CodeTypeDeclaration.Members.Add (method);
			CodeTypeDeclaration.Members.Add (methodBegin);
			CodeTypeDeclaration.Members.Add (methodEnd);
			
			return method;
		}		
		void GenerateReturnAttributes (XmlMembersMapping members, XmlMemberMapping member, SoapBindingUse use, CodeMemberMethod method)
		{
			if (use == SoapBindingUse.Literal)
				xmlExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, member, members.Namespace, (member.ElementName != method.Name + "Result"));
			else
				soapExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, member, (member.ElementName != method.Name + "Result"));
		}
		CodeMemberMethod GenerateMethod (CodeIdentifiers memberIds, SoapOperationBinding soapOper, SoapBodyBinding bodyBinding, XmlMembersMapping inputMembers, XmlMembersMapping outputMembers)
		{
			CodeIdentifiers pids = new CodeIdentifiers ();
			CodeMemberMethod method = new CodeMemberMethod ();
			CodeMemberMethod methodBegin = new CodeMemberMethod ();
			CodeMemberMethod methodEnd = new CodeMemberMethod ();
			method.Attributes = MemberAttributes.Public | MemberAttributes.Final;
			methodBegin.Attributes = MemberAttributes.Public | MemberAttributes.Final;
			methodEnd.Attributes = MemberAttributes.Public | MemberAttributes.Final;
			
			SoapBindingStyle style = soapOper.Style != SoapBindingStyle.Default ? soapOper.Style : soapBinding.Style;
			
			// Find unique names for temporary variables
			
			for (int n=0; n<inputMembers.Count; n++)
				pids.AddUnique (inputMembers[n].MemberName, inputMembers[n]);

			if (outputMembers != null)
				for (int n=0; n<outputMembers.Count; n++)
					pids.AddUnique (outputMembers[n].MemberName, outputMembers[n]);
				
			string varAsyncResult = pids.AddUnique ("asyncResult","asyncResult");
			string varResults = pids.AddUnique ("results","results");
			string varCallback = pids.AddUnique ("callback","callback");
			string varAsyncState = pids.AddUnique ("asyncState","asyncState");

			string messageName = memberIds.AddUnique(CodeIdentifier.MakeValid(Operation.Name),method);

			method.Name = CodeIdentifier.MakeValid(Operation.Name);
			if (method.Name == ClassName) method.Name += "1";
			methodBegin.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("Begin" + method.Name),method);
			methodEnd.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + method.Name),method);

			method.ReturnType = new CodeTypeReference (typeof(void));
			methodEnd.ReturnType = new CodeTypeReference (typeof(void));
			methodEnd.Parameters.Add (new CodeParameterDeclarationExpression (typeof (IAsyncResult),varAsyncResult));

			CodeExpression[] paramArray = new CodeExpression [inputMembers.Count];
			CodeParameterDeclarationExpression[] outParams = new CodeParameterDeclarationExpression [outputMembers != null ? outputMembers.Count : 0];

			for (int n=0; n<inputMembers.Count; n++)
			{
				CodeParameterDeclarationExpression param = GenerateParameter (inputMembers[n], FieldDirection.In);
				method.Parameters.Add (param);
				GenerateMemberAttributes (inputMembers, inputMembers[n], bodyBinding.Use, param);
				methodBegin.Parameters.Add (GenerateParameter (inputMembers[n], FieldDirection.In));
				paramArray [n] = new CodeVariableReferenceExpression (param.Name);
			}

			if (outputMembers != null)
			{
				bool hasReturn = false;
				for (int n=0; n<outputMembers.Count; n++)
				{
					CodeParameterDeclarationExpression cpd = GenerateParameter (outputMembers[n], FieldDirection.Out);
					outParams [n] = cpd;
					
					bool found = false;
					foreach (CodeParameterDeclarationExpression ip in method.Parameters)
					{
						if (ip.Name == cpd.Name && ip.Type.BaseType == cpd.Type.BaseType) {
							ip.Direction = FieldDirection.Ref;
							methodEnd.Parameters.Add (GenerateParameter (outputMembers[n], FieldDirection.Out));
							found = true;
							break;
						}
					}
					
					if (found) continue;
	
					if (!hasReturn) 
					{
						hasReturn = true;
						method.ReturnType = cpd.Type;
						methodEnd.ReturnType = cpd.Type;
						GenerateReturnAttributes (outputMembers, outputMembers[n], bodyBinding.Use, method);
						outParams [n] = null;
						continue;
					}
					
					method.Parameters.Add (cpd);
					GenerateMemberAttributes (outputMembers, outputMembers[n], bodyBinding.Use, cpd);
					methodEnd.Parameters.Add (GenerateParameter (outputMembers[n], FieldDirection.Out));
				}
			}
			
			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (AsyncCallback),varCallback));
			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (object),varAsyncState));
			methodBegin.ReturnType = new CodeTypeReference (typeof(IAsyncResult));

			// Array of input parameters
			
			CodeArrayCreateExpression methodParams;
			if (paramArray.Length > 0)
				methodParams = new CodeArrayCreateExpression (typeof(object), paramArray);
			else
				methodParams = new CodeArrayCreateExpression (typeof(object), 0);

			// Assignment of output parameters
			
			CodeStatementCollection outAssign = new CodeStatementCollection ();
			CodeVariableReferenceExpression arrVar = new CodeVariableReferenceExpression (varResults);
			for (int n=0; n<outParams.Length; n++)
			{
				CodeExpression index = new CodePrimitiveExpression (n);
				if (outParams[n] == null)
				{
					CodeExpression res = new CodeCastExpression (method.ReturnType, new CodeArrayIndexerExpression (arrVar, index));
					outAssign.Add (new CodeMethodReturnStatement (res));
				}
				else
				{
					CodeExpression res = new CodeCastExpression (outParams[n].Type, new CodeArrayIndexerExpression (arrVar, index));
					CodeExpression var = new CodeVariableReferenceExpression (outParams[n].Name);
					outAssign.Insert (0, new CodeAssignStatement (var, res));
				}
			}
			
			if (Style == ServiceDescriptionImportStyle.Client) 
			{
				// Invoke call
				
				CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();
				CodePrimitiveExpression varMsgName = new CodePrimitiveExpression (messageName);
				CodeMethodInvokeExpression inv;
				CodeVariableDeclarationStatement dec;
	
				inv = new CodeMethodInvokeExpression (ethis, "Invoke", varMsgName, methodParams);
				if (outputMembers != null && outputMembers.Count > 0)
				{
					dec = new CodeVariableDeclarationStatement (typeof(object[]), varResults, inv);
					method.Statements.Add (dec);
					method.Statements.AddRange (outAssign);
				}
				else
					method.Statements.Add (inv);
				
				// Begin Invoke Call
				
				CodeExpression expCallb = new CodeVariableReferenceExpression (varCallback);
				CodeExpression expAsyncs = new CodeVariableReferenceExpression (varAsyncState);
				inv = new CodeMethodInvokeExpression (ethis, "BeginInvoke", varMsgName, methodParams, expCallb, expAsyncs);
				methodBegin.Statements.Add (new CodeMethodReturnStatement (inv));
				
				// End Invoke call
				
				CodeExpression varAsyncr = new CodeVariableReferenceExpression (varAsyncResult);
				inv = new CodeMethodInvokeExpression (ethis, "EndInvoke", varAsyncr);
				if (outputMembers != null && outputMembers.Count > 0)
				{
					dec = new CodeVariableDeclarationStatement (typeof(object[]), varResults, inv);
					methodEnd.Statements.Add (dec);
					methodEnd.Statements.AddRange (outAssign);
				}
				else
					methodEnd.Statements.Add (inv);
			}
			else {
				method.Attributes = MemberAttributes.Public | MemberAttributes.Abstract;
			}
			
			// Attributes
			
			ImportHeaders (method);
			
			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.WebMethodAttribute");
			if (messageName != method.Name) att.Arguments.Add (GetArg ("MessageName",messageName));
			AddCustomAttribute (method, att, (Style == ServiceDescriptionImportStyle.Server));
			
			if (style == SoapBindingStyle.Rpc)
			{
				att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapRpcMethodAttribute");
				att.Arguments.Add (GetArg (soapOper.SoapAction));
				if (inputMembers.ElementName != method.Name) att.Arguments.Add (GetArg ("RequestElementName", inputMembers.ElementName));
				if (outputMembers != null && outputMembers.ElementName != (method.Name + "Response")) att.Arguments.Add (GetArg ("ResponseElementName", outputMembers.ElementName));
				att.Arguments.Add (GetArg ("RequestNamespace", inputMembers.Namespace));
				if (outputMembers != null) att.Arguments.Add (GetArg ("ResponseNamespace", outputMembers.Namespace));
				if (outputMembers == null) att.Arguments.Add (GetArg ("OneWay", true));
			}
			else
			{
				if (outputMembers != null && (inputMembers.ElementName == "" && outputMembers.ElementName != "" || 
					inputMembers.ElementName != "" && outputMembers.ElementName == ""))
					throw new InvalidOperationException ("Parameter style is not the same for the input message and output message");
	
				att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapDocumentMethodAttribute");
				att.Arguments.Add (GetArg (soapOper.SoapAction));
				if (inputMembers.ElementName != "") {
					if (inputMembers.ElementName != method.Name) att.Arguments.Add (GetArg ("RequestElementName", inputMembers.ElementName));
					if (outputMembers != null && outputMembers.ElementName != (method.Name + "Response")) att.Arguments.Add (GetArg ("ResponseElementName", outputMembers.ElementName));
					att.Arguments.Add (GetArg ("RequestNamespace", inputMembers.Namespace));
					if (outputMembers != null) att.Arguments.Add (GetArg ("ResponseNamespace", outputMembers.Namespace));
					att.Arguments.Add (GetEnumArg ("ParameterStyle", "System.Web.Services.Protocols.SoapParameterStyle", "Wrapped"));
				}
				else
					att.Arguments.Add (GetEnumArg ("ParameterStyle", "System.Web.Services.Protocols.SoapParameterStyle", "Bare"));
					
				if (outputMembers == null) att.Arguments.Add (GetArg ("OneWay", true));
					
				att.Arguments.Add (GetEnumArg ("Use", "System.Web.Services.Description.SoapBindingUse", bodyBinding.Use.ToString()));
			}
			
			AddCustomAttribute (method, att, true);
			
			CodeTypeDeclaration.Members.Add (method);
			
			if (Style == ServiceDescriptionImportStyle.Client) {
				CodeTypeDeclaration.Members.Add (methodBegin);
				CodeTypeDeclaration.Members.Add (methodEnd);
			}
			
			return method;
		}
		void GenerateWriteMessage (XmlMembersMapping membersMap)
		{
			if (membersMap.HasWrapperElement) {
				WriteLine ("TopLevelElement ();");
				WriteLine ("WriteStartElement (" + GetLiteral (membersMap.ElementName) + ", " + GetLiteral (membersMap.Namespace) + ", (" + GetLiteral(_format == SerializationFormat.Encoded) + "));");

/*				WriteLineInd ("if (Writer.LookupPrefix (XmlSchema.Namespace) == null)");
				WriteLine ("WriteAttribute (\"xmlns\",\"xsd\",XmlSchema.Namespace,XmlSchema.Namespace);");
				Unindent ();
	
				WriteLineInd ("if (Writer.LookupPrefix (XmlSchema.InstanceNamespace) == null)");
				WriteLine ("WriteAttribute (\"xmlns\",\"xsi\",XmlSchema.InstanceNamespace,XmlSchema.InstanceNamespace);");
				Unindent ();
*/
			}
			
			GenerateWriteObjectElement (membersMap, "pars", true);

			if (membersMap.HasWrapperElement)
				WriteLine ("WriteEndElement();");
		}
Example #36
0
        void ExportMembersMapping(XmlMembersMapping xmlMembersMapping, bool exportEnclosingType)
        {
            ClassMap cmap = (ClassMap)xmlMembersMapping.ObjectMap;

            if (xmlMembersMapping.HasWrapperElement && exportEnclosingType)
            {
                XmlSchema            schema = GetSchema(xmlMembersMapping.Namespace);
                XmlSchemaComplexType stype  = new XmlSchemaComplexType();

                XmlSchemaSequence     particle;
                XmlSchemaAnyAttribute anyAttribute;
                ExportMembersMapSchema(schema, cmap, null, stype.Attributes, out particle, out anyAttribute);
                stype.Particle     = particle;
                stype.AnyAttribute = anyAttribute;

                if (encodedFormat)
                {
                    stype.Name = xmlMembersMapping.ElementName;
                    schema.Items.Add(stype);
                }
                else
                {
                    XmlSchemaElement selem = new XmlSchemaElement();
                    selem.Name       = xmlMembersMapping.ElementName;
                    selem.SchemaType = stype;
                    schema.Items.Add(selem);
                }
            }
            else
            {
                ICollection members = cmap.ElementMembers;
                if (members != null)
                {
                    foreach (XmlTypeMapMemberElement member in members)
                    {
                        if (member is XmlTypeMapMemberAnyElement && member.TypeData.IsListType)
                        {
                            XmlSchema         mschema = GetSchema(xmlMembersMapping.Namespace);
                            XmlSchemaParticle par     = GetSchemaArrayElement(mschema, member.ElementInfo);
                            if (par is XmlSchemaAny)
                            {
                                XmlSchemaComplexType ct = FindComplexType(mschema.Items, "any");
                                if (ct != null)
                                {
                                    continue;
                                }

                                ct         = new XmlSchemaComplexType();
                                ct.Name    = "any";
                                ct.IsMixed = true;
                                XmlSchemaSequence seq = new XmlSchemaSequence();
                                ct.Particle = seq;
                                seq.Items.Add(par);
                                mschema.Items.Add(ct);
                                continue;
                            }
                        }


                        XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo)member.ElementInfo [0];
                        XmlSchema             schema;

                        if (encodedFormat)
                        {
                            schema = GetSchema(xmlMembersMapping.Namespace);
                            ImportNamespace(schema, XmlSerializer.EncodingNamespace);
                        }
                        else
                        {
                            schema = GetSchema(einfo.Namespace);
                        }


                        XmlSchemaElement exe = FindElement(schema.Items, einfo.ElementName);
                        XmlSchemaElement elem;

                        XmlSchemaObjectContainer container = null;
                        // In encoded format, the schema elements are not needed
                        if (!encodedFormat)
                        {
                            container = new XmlSchemaObjectContainer(schema);
                        }

                        Type memType = member.GetType();
                        if (member is XmlTypeMapMemberFlatList)
                        {
                            throw new InvalidOperationException("Unwrapped arrays not supported as parameters");
                        }
                        else if (memType == typeof(XmlTypeMapMemberElement))
                        {
                            elem = (XmlSchemaElement)GetSchemaElement(schema,
                                                                      einfo, member.DefaultValue, false, container);
                        }
                        else
                        {
                            elem = (XmlSchemaElement)GetSchemaElement(schema,
                                                                      einfo, false, container);
                        }

                        if (exe != null)
                        {
                            if (exe.SchemaTypeName.Equals(elem.SchemaTypeName))
                            {
                                schema.Items.Remove(elem);
                            }
                            else
                            {
                                string s = "The XML element named '" + einfo.ElementName + "' ";
                                s += "from namespace '" + schema.TargetNamespace + "' references distinct types " + elem.SchemaTypeName.Name + " and " + exe.SchemaTypeName.Name + ". ";
                                s += "Use XML attributes to specify another XML name or namespace for the element or types.";
                                throw new InvalidOperationException(s);
                            }
                        }
                    }
                }
            }

            CompileSchemas();
        }
Example #37
0
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping,
                                  bool exportEnclosingType)
 {
     _exporter.ExportMembersMapping(xmlMembersMapping, exportEnclosingType);
 }
Example #38
0
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
 {
     _exporter.ExportMembersMapping(xmlMembersMapping, false);
 }
		string GenerateReadMessage (XmlMembersMapping typeMap)
		{
			WriteLine ("object[] parameters = new object[" + typeMap.Count + "];");
			WriteLine ("");

			if (typeMap.HasWrapperElement)
			{
				if (_format == SerializationFormat.Encoded)
				{
					WriteLine ("while (Reader.NodeType == System.Xml.XmlNodeType.Element)");
					WriteLineInd ("{");
					WriteLine ("string root = Reader.GetAttribute (\"root\", " + GetLiteral(XmlSerializer.EncodingNamespace) + ");");
					WriteLine ("if (root == null || System.Xml.XmlConvert.ToBoolean(root)) break;");
					WriteLine ("ReadReferencedElement ();");
					WriteLine ("Reader.MoveToContent ();");
					WriteLineUni ("}");
					WriteLine ("");
					WriteLine ("if (Reader.NodeType != System.Xml.XmlNodeType.EndElement)");
					WriteLineInd ("{");
					WriteLineInd ("if (Reader.IsEmptyElement) {");
					WriteLine ("Reader.Skip();");
					WriteLine ("Reader.MoveToContent();");
					WriteLineUni ("}");
					WriteLineInd ("else {");
					WriteLine ("Reader.ReadStartElement();");
					GenerateReadMembers (typeMap, (ClassMap)typeMap.ObjectMap, "parameters", true, false);
					WriteLine ("ReadEndElement();");
					WriteLineUni ("}");
					WriteLine ("");
					WriteLine ("Reader.MoveToContent();");
					WriteLineUni ("}");
				}
				else
				{
					// bug #79988: out parameters need to be initialized if 
					// they are value types
					ClassMap classMap = (ClassMap) typeMap.ObjectMap;
					ArrayList members = classMap.AllMembers;
					for (int n = 0; n < members.Count; n++) {
						XmlTypeMapMember mem = (XmlTypeMapMember) members [n];
						if (!mem.IsReturnValue && mem.TypeData.IsValueType)
							GenerateSetMemberValueFromAttr (mem, "parameters",
								String.Format ("({0}) Activator.CreateInstance(typeof({0}), true)", mem.TypeData.FullTypeName), true);
					}

					WriteLine ("while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && Reader.ReadState == ReadState.Interactive)");
					WriteLineInd ("{");
					WriteLine ("if (Reader.IsStartElement(" + GetLiteral(typeMap.ElementName) + ", " + GetLiteral(typeMap.Namespace) + "))");
					WriteLineInd ("{");
					bool dummy = false;
					GenerateReadAttributeMembers (typeMap, (ClassMap)typeMap.ObjectMap, "parameters", true, ref dummy);
					WriteLine ("if (Reader.IsEmptyElement)");
					WriteLineInd ("{");
					WriteLine ("Reader.Skip(); Reader.MoveToContent(); continue;");
					WriteLineUni ("}");
					WriteLine ("Reader.ReadStartElement();");
					GenerateReadMembers (typeMap, (ClassMap)typeMap.ObjectMap, "parameters", true, false);
					WriteLine ("ReadEndElement();");
					WriteLine ("break;");
					WriteLineUni ("}");
					WriteLineInd ("else ");
					WriteLine ("UnknownNode(null);");
					Unindent ();
					WriteLine ("");
					WriteLine ("Reader.MoveToContent();");
					WriteLineUni ("}");
				}
			}
			else
				GenerateReadMembers (typeMap, (ClassMap)typeMap.ObjectMap, "parameters", true, _format == SerializationFormat.Encoded);

			if (_format == SerializationFormat.Encoded)
				WriteLine ("ReadReferencedElements();");

			return "parameters";
		}
        /// <include file='doc\SoapReflectionImporter.uex' path='docs/doc[@for="SoapReflectionImporter.ImportMembersMapping3"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate, XmlMappingAccess access) {
            ElementAccessor element = new ElementAccessor();
            element.IsSoap = true;
            element.Name = elementName == null || elementName.Length == 0 ? elementName : XmlConvert.EncodeLocalName(elementName);

            element.Mapping = ImportMembersMapping(members, ns, hasWrapperElement, writeAccessors, validate);
            element.Mapping.TypeName = elementName;
            element.Namespace = element.Mapping.Namespace == null ? ns : element.Mapping.Namespace;
            element.Form = XmlSchemaForm.Qualified;
            XmlMembersMapping xmlMapping = new XmlMembersMapping(typeScope, element, access);
            xmlMapping.IsSoap = true;
            xmlMapping.GenerateSerializer = true;
            return xmlMapping;
        }
Example #41
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);
		}
        /// <summary>Adds an element declaration to the applicable <see cref="T:System.Xml.Schema.XmlSchema" /> for each of the element parts of a literal SOAP message definition, and specifies whether enclosing elements are included.</summary>
        /// <param name="xmlMembersMapping">The internal mapping between a .NET Framework type and an XML schema element.</param>
        /// <param name="exportEnclosingType">true if the schema elements that enclose the schema are to be included; otherwise, false.</param>
        public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping, bool exportEnclosingType)
        {
            ClassMap classMap = (ClassMap)xmlMembersMapping.ObjectMap;

            if (xmlMembersMapping.HasWrapperElement && exportEnclosingType)
            {
                XmlSchema             schema = this.GetSchema(xmlMembersMapping.Namespace);
                XmlSchemaComplexType  xmlSchemaComplexType = new XmlSchemaComplexType();
                XmlSchemaSequence     particle;
                XmlSchemaAnyAttribute anyAttribute;
                this.ExportMembersMapSchema(schema, classMap, null, xmlSchemaComplexType.Attributes, out particle, out anyAttribute);
                xmlSchemaComplexType.Particle     = particle;
                xmlSchemaComplexType.AnyAttribute = anyAttribute;
                if (this.encodedFormat)
                {
                    xmlSchemaComplexType.Name = xmlMembersMapping.ElementName;
                    schema.Items.Add(xmlSchemaComplexType);
                }
                else
                {
                    XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
                    xmlSchemaElement.Name       = xmlMembersMapping.ElementName;
                    xmlSchemaElement.SchemaType = xmlSchemaComplexType;
                    schema.Items.Add(xmlSchemaElement);
                }
            }
            else
            {
                ICollection elementMembers = classMap.ElementMembers;
                if (elementMembers != null)
                {
                    foreach (object obj in elementMembers)
                    {
                        XmlTypeMapMemberElement xmlTypeMapMemberElement = (XmlTypeMapMemberElement)obj;
                        if (xmlTypeMapMemberElement is XmlTypeMapMemberAnyElement && xmlTypeMapMemberElement.TypeData.IsListType)
                        {
                            XmlSchema         schema2            = this.GetSchema(xmlMembersMapping.Namespace);
                            XmlSchemaParticle schemaArrayElement = this.GetSchemaArrayElement(schema2, xmlTypeMapMemberElement.ElementInfo);
                            if (schemaArrayElement is XmlSchemaAny)
                            {
                                XmlSchemaComplexType xmlSchemaComplexType2 = this.FindComplexType(schema2.Items, "any");
                                if (xmlSchemaComplexType2 != null)
                                {
                                    continue;
                                }
                                xmlSchemaComplexType2         = new XmlSchemaComplexType();
                                xmlSchemaComplexType2.Name    = "any";
                                xmlSchemaComplexType2.IsMixed = true;
                                XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
                                xmlSchemaComplexType2.Particle = xmlSchemaSequence;
                                xmlSchemaSequence.Items.Add(schemaArrayElement);
                                schema2.Items.Add(xmlSchemaComplexType2);
                                continue;
                            }
                        }
                        XmlTypeMapElementInfo xmlTypeMapElementInfo = (XmlTypeMapElementInfo)xmlTypeMapMemberElement.ElementInfo[0];
                        XmlSchema             schema3;
                        if (this.encodedFormat)
                        {
                            schema3 = this.GetSchema(xmlMembersMapping.Namespace);
                            this.ImportNamespace(schema3, "http://schemas.xmlsoap.org/soap/encoding/");
                        }
                        else
                        {
                            schema3 = this.GetSchema(xmlTypeMapElementInfo.Namespace);
                        }
                        XmlSchemaElement xmlSchemaElement2 = this.FindElement(schema3.Items, xmlTypeMapElementInfo.ElementName);
                        XmlSchemaExporter.XmlSchemaObjectContainer container = null;
                        if (!this.encodedFormat)
                        {
                            container = new XmlSchemaExporter.XmlSchemaObjectContainer(schema3);
                        }
                        Type type = xmlTypeMapMemberElement.GetType();
                        if (xmlTypeMapMemberElement is XmlTypeMapMemberFlatList)
                        {
                            throw new InvalidOperationException("Unwrapped arrays not supported as parameters");
                        }
                        XmlSchemaElement xmlSchemaElement3;
                        if (type == typeof(XmlTypeMapMemberElement))
                        {
                            xmlSchemaElement3 = (XmlSchemaElement)this.GetSchemaElement(schema3, xmlTypeMapElementInfo, xmlTypeMapMemberElement.DefaultValue, false, container);
                        }
                        else
                        {
                            xmlSchemaElement3 = (XmlSchemaElement)this.GetSchemaElement(schema3, xmlTypeMapElementInfo, false, container);
                        }
                        if (xmlSchemaElement2 != null)
                        {
                            if (!xmlSchemaElement2.SchemaTypeName.Equals(xmlSchemaElement3.SchemaTypeName))
                            {
                                string text  = "The XML element named '" + xmlTypeMapElementInfo.ElementName + "' ";
                                string text2 = text;
                                text = string.Concat(new string[]
                                {
                                    text2,
                                    "from namespace '",
                                    schema3.TargetNamespace,
                                    "' references distinct types ",
                                    xmlSchemaElement3.SchemaTypeName.Name,
                                    " and ",
                                    xmlSchemaElement2.SchemaTypeName.Name,
                                    ". "
                                });
                                text += "Use XML attributes to specify another XML name or namespace for the element or types.";
                                throw new InvalidOperationException(text);
                            }
                            schema3.Items.Remove(xmlSchemaElement3);
                        }
                    }
                }
            }
            this.CompileSchemas();
        }
		void GenerateMemberAttributes (XmlMembersMapping members, XmlMemberMapping member, SoapBindingUse use, CodeParameterDeclarationExpression param)
		{
			if (use == SoapBindingUse.Literal)
				xmlExporter.AddMappingMetadata (param.CustomAttributes, member, members.Namespace);
			else
				soapExporter.AddMappingMetadata (param.CustomAttributes, member);
		}
 public string ExportAnyType(XmlMembersMapping members)
 {
     if (((members.Count != 1) || !members[0].Any) || (members[0].ElementName.Length != 0))
     {
         return null;
     }
     XmlMemberMapping mapping = members[0];
     string ns = mapping.Namespace;
     bool isArrayLike = mapping.Mapping.TypeDesc.IsArrayLike;
     bool mixed = (isArrayLike && (mapping.Mapping.TypeDesc.ArrayElementTypeDesc != null)) ? mapping.Mapping.TypeDesc.ArrayElementTypeDesc.IsMixed : mapping.Mapping.TypeDesc.IsMixed;
     if (mixed && mapping.Mapping.TypeDesc.IsMixed)
     {
         isArrayLike = true;
     }
     string str2 = mixed ? "any" : (isArrayLike ? "anyElements" : "anyElement");
     string name = str2;
     int num = 0;
     XmlSchema schema = this.schemas[ns];
     if (schema != null)
     {
         while (true)
         {
             XmlSchemaType schemaType = FindSchemaType(name, schema.Items);
             if (schemaType == null)
             {
                 break;
             }
             if (IsAnyType(schemaType, mixed, isArrayLike))
             {
                 return name;
             }
             num++;
             name = str2 + num.ToString(CultureInfo.InvariantCulture);
         }
     }
     XmlSchemaComplexType item = new XmlSchemaComplexType {
         Name = name,
         IsMixed = mixed
     };
     XmlSchemaSequence sequence = new XmlSchemaSequence();
     XmlSchemaAny any = new XmlSchemaAny {
         MinOccurs = 0M
     };
     if (isArrayLike)
     {
         any.MaxOccurs = 79228162514264337593543950335M;
     }
     sequence.Items.Add(any);
     item.Particle = sequence;
     this.AddSchemaItem(item, ns, null);
     return name;
 }
Example #45
0
		XmlMembersMapping ImportMembersMapping (string elementName, 
			string ns, 
			XmlReflectionMember[] members, 
			bool hasWrapperElement, 
			bool writeAccessors, 
			bool validate,
			XmlMappingAccess access)
		{
//			Reset ();	Disabled. See ChangeLog

			ArrayList mapping = new ArrayList ();
			for (int n=0; n<members.Length; n++)
			{
				if (members[n].XmlAttributes.XmlIgnore) continue;
				XmlTypeMapMember mapMem = CreateMapMember (null, members[n], ns);
				mapMem.GlobalIndex = n;
				mapMem.CheckOptionalValueType (members);
				mapping.Add (new XmlMemberMapping (members[n].MemberName, ns, mapMem, false));
			}
			elementName = XmlConvert.EncodeLocalName (elementName);
			XmlMembersMapping mps = new XmlMembersMapping (elementName, ns, hasWrapperElement, false, (XmlMemberMapping[])mapping.ToArray (typeof(XmlMemberMapping)));
			mps.RelatedMaps = relatedMaps;
			mps.Format = SerializationFormat.Literal;
			Type[] extraTypes = includedTypes != null ? (Type[])includedTypes.ToArray(typeof(Type)) : null;
#if !NET_2_1
			mps.Source = new MembersSerializationSource (elementName, hasWrapperElement, members, false, true, ns, extraTypes);
			if (allowPrivateTypes) mps.Source.CanBeGenerated = false;
#endif
			return mps;
		}
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
 {
     this.ExportMembersMapping(xmlMembersMapping, true);
 }
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping, bool exportEnclosingType)
 {
     xmlMembersMapping.CheckShallow();
     MembersMapping mapping = (MembersMapping) xmlMembersMapping.Accessor.Mapping;
     this.CheckScope(xmlMembersMapping.Scope);
     if (mapping.HasWrapperElement && exportEnclosingType)
     {
         this.ExportElement(xmlMembersMapping.Accessor);
     }
     else
     {
         foreach (MemberMapping mapping2 in mapping.Members)
         {
             if (mapping2.Attribute != null)
             {
                 throw new InvalidOperationException(Res.GetString("XmlBareAttributeMember", new object[] { mapping2.Attribute.Name }));
             }
             if (mapping2.Text != null)
             {
                 throw new InvalidOperationException(Res.GetString("XmlBareTextMember", new object[] { mapping2.Text.Name }));
             }
             if ((mapping2.Elements != null) && (mapping2.Elements.Length != 0))
             {
                 if (mapping2.TypeDesc.IsArrayLike && !(mapping2.Elements[0].Mapping is ArrayMapping))
                 {
                     throw new InvalidOperationException(Res.GetString("XmlIllegalArrayElement", new object[] { mapping2.Elements[0].Name }));
                 }
                 if (exportEnclosingType)
                 {
                     this.ExportElement(mapping2.Elements[0]);
                 }
                 else
                 {
                     this.ExportMapping(mapping2.Elements[0].Mapping, mapping2.Elements[0].Namespace, mapping2.Elements[0].Any);
                 }
             }
         }
     }
     this.ExportRootIfNecessary(xmlMembersMapping.Scope);
 }
Example #48
0
        public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
        {
            CodeTypeDeclaration dummyClass = new CodeTypeDeclaration();

            ExportMembersMapCode(dummyClass, (ClassMap)xmlMembersMapping.ObjectMap, xmlMembersMapping.Namespace, null);
        }
 void CreateLiteralMessage(Message message, MessageBinding messageBinding, XmlMembersMapping members, bool wrapped, bool rpc) {
     if (members.Count == 1 && members[0].Any && members[0].ElementName.Length == 0 && !wrapped) {
         string typeName = SchemaExporter.ExportAnyType(members[0].Namespace);
         MessagePart part = new MessagePart();
         part.Name = members[0].MemberName;
         part.Type = new XmlQualifiedName(typeName, members[0].Namespace);
         message.Parts.Add(part);
     }
     else {
         SchemaExporter.ExportMembersMapping(members, !rpc);
         if (wrapped) {
             MessagePart part = new MessagePart();
             part.Name = "parameters";
             part.Element = new XmlQualifiedName(members.XsdElementName, members.Namespace);
             message.Parts.Add(part);
         }
         else {
             for (int i = 0; i < members.Count; i++) {
                 XmlMemberMapping member = members[i];
                 MessagePart part = new MessagePart();
                 if (rpc) {
                     // Generate massage part with the type attribute
                     if (member.TypeName == null || member.TypeName.Length == 0) {
                         throw new InvalidOperationException(Res.GetString(Res.WsdlGenRpcLitAnonimousType, Method.DeclaringType.Name, Method.Name, member.MemberName));
                     }
                     part.Name = member.XsdElementName;
                     part.Type = new XmlQualifiedName(member.TypeName, member.TypeNamespace);
                 }
                 else {
                     part.Name = XmlConvert.EncodeLocalName(member.MemberName);
                     part.Element = new XmlQualifiedName(member.XsdElementName, member.Namespace);
                 }
                 message.Parts.Add(part);
             }
         }
     }
     messageBinding.Extensions.Add(CreateSoapBodyBinding(SoapBindingUse.Literal, rpc ? members.Namespace : null));
 }
Example #50
0
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
 {
     codeGenerator.ExportMembersMapping(xmlMembersMapping);
 }
 string GenerateMembersElement(XmlMembersMapping xmlMembersMapping) {
     if (xmlMembersMapping.Accessor.IsSoap)
         return GenerateEncodedMembersElement(xmlMembersMapping);
     else
         return GenerateLiteralMembersElement(xmlMembersMapping);
 }
Example #52
0
 public XmlQualifiedName ExportTypeMapping(XmlMembersMapping xmlMembersMapping)
 {
     throw new NotImplementedException();
 }
        string GenerateEncodedMembersElement(XmlMembersMapping xmlMembersMapping) {
            ElementAccessor element = xmlMembersMapping.Accessor;
            MembersMapping membersMapping = (MembersMapping)element.Mapping;
            MemberMapping[] mappings = membersMapping.Members;
            bool hasWrapperElement = membersMapping.HasWrapperElement;
            bool writeAccessors = membersMapping.WriteAccessors;
            string methodName = NextMethodName(element.Name);
            Writer.WriteLine();
            Writer.Write("public object[] ");
            Writer.Write(methodName);
            Writer.WriteLine("() {");
            Writer.Indent++;

            Writer.WriteLine("Reader.MoveToContent();");

            Writer.Write("object[] p = new object[");
            Writer.Write(mappings.Length.ToString(CultureInfo.InvariantCulture));
            Writer.WriteLine("];");
            InitializeValueTypes("p", mappings);

            if (hasWrapperElement) {
                WriteReadNonRoots();

                if (membersMapping.ValidateRpcWrapperElement) {
                    Writer.Write("if (!");
                    WriteXmlNodeEqual("Reader", element.Name, element.Form == XmlSchemaForm.Qualified ? element.Namespace : "");
                    Writer.WriteLine(") throw CreateUnknownNodeException();");
                }
                Writer.WriteLine("bool isEmptyWrapper = Reader.IsEmptyElement;");
                Writer.WriteLine("Reader.ReadStartElement();");
            }

            Member[] members = new Member[mappings.Length];
            for (int i = 0; i < mappings.Length; i++) {
                MemberMapping mapping = mappings[i];
                string source = "p[" + i.ToString(CultureInfo.InvariantCulture) + "]";
                string arraySource = source;
                if (mapping.Xmlns != null) {
                    arraySource = "((" + mapping.TypeDesc.CSharpName + ")" + source + ")";
                }
                Member member = new Member(this,source, arraySource, "a", i, mapping);
                if (!mapping.IsSequence)
                    member.ParamsReadSource = "paramsRead[" + i.ToString(CultureInfo.InvariantCulture) + "]";
                members[i] = member;

                if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) {
                    string nameSpecified = mapping.Name + "Specified";
                    for (int j = 0; j < mappings.Length; j++) {
                        if (mappings[j].Name == nameSpecified) {
                            member.CheckSpecifiedSource = "p[" + j.ToString(CultureInfo.InvariantCulture) + "]";
                            break;
                        }
                    }
                }

            }

            string fixupMethodName = "fixup_" + methodName;
            bool anyFixups = WriteMemberFixupBegin(members, fixupMethodName, "p");

            if (members.Length > 0 && members[0].Mapping.IsReturnValue) Writer.WriteLine("IsReturnValue = true;");

            string checkTypeHrefSource = (!hasWrapperElement && !writeAccessors) ? "hrefList" : null;
            if (checkTypeHrefSource != null)
                WriteInitCheckTypeHrefList(checkTypeHrefSource);
                     
            WriteParamsRead(mappings.Length);
            int loopIndex = WriteWhileNotLoopStart();
            Writer.Indent++;

            string unrecognizedElementSource = checkTypeHrefSource == null ? "UnknownNode((object)p);" : "if (Reader.GetAttribute(\"id\", null) != null) { ReadReferencedElement(); } else { UnknownNode((object)p); }";
            WriteMemberElements(members, unrecognizedElementSource, "UnknownNode((object)p);", null, null, checkTypeHrefSource);
            Writer.WriteLine("Reader.MoveToContent();");

            WriteWhileLoopEnd(loopIndex);

            if (hasWrapperElement)
                Writer.WriteLine("if (!isEmptyWrapper) ReadEndElement();");

            if (checkTypeHrefSource != null)
                WriteHandleHrefList(members, checkTypeHrefSource);

            Writer.WriteLine("ReadReferencedElements();");
            Writer.WriteLine("return p;");

            Writer.Indent--;
            Writer.WriteLine("}");

            if (anyFixups) WriteFixupMethod(fixupMethodName, members, "object[]", false, false, "p");
          
            return methodName;
        }
Example #54
0
 public string ExportAnyType(XmlMembersMapping members)
 {
     throw new NotImplementedException();
 }
		public void ExportMembersMapping (XmlMembersMapping xmlMembersMapping)
		{
			codeGenerator.ExportMembersMapping (xmlMembersMapping);
		}
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
 {
     this.ExportMembersMapping(xmlMembersMapping, false);
 }
        string GenerateMembersElement(XmlMembersMapping xmlMembersMapping) {
            ElementAccessor element = xmlMembersMapping.Accessor;
            MembersMapping mapping = (MembersMapping)element.Mapping;
            bool hasWrapperElement = mapping.HasWrapperElement;
            bool writeAccessors = mapping.WriteAccessors;
            bool isRpc = xmlMembersMapping.IsSoap && writeAccessors;
            string methodName = NextMethodName(element.Name);
            Writer.WriteLine();
            Writer.Write("public void ");
            Writer.Write(methodName);
            Writer.WriteLine("(object[] p) {");
            Writer.Indent++;

            Writer.WriteLine("WriteStartDocument();");

            if (!mapping.IsSoap) {
                Writer.WriteLine("TopLevelElement();");
            }

            // in the top-level method add check for the parameters length, 
            // because visual basic does not have a concept of an <out> parameter it uses <ByRef> instead
            // so sometime we think that we have more parameters then supplied
            Writer.WriteLine("int pLength = p.Length;");

            if (hasWrapperElement) {
                WriteStartElement(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""), mapping.IsSoap);

                int xmlnsMember = FindXmlnsIndex(mapping.Members);
                if (xmlnsMember >= 0) {
                    MemberMapping member = mapping.Members[xmlnsMember];
                    string source = "((" + typeof(XmlSerializerNamespaces).FullName + ")p[" + xmlnsMember.ToString(CultureInfo.InvariantCulture) + "])";

                    Writer.Write("if (pLength > ");
                    Writer.Write(xmlnsMember.ToString(CultureInfo.InvariantCulture));
                    Writer.WriteLine(") {");
                    Writer.Indent++;
                    WriteNamespaces(source);
                    Writer.Indent--;
                    Writer.WriteLine("}");
                }

                for (int i = 0; i < mapping.Members.Length; i++) {
                    MemberMapping member = mapping.Members[i];
                    
                    if (member.Attribute != null && !member.Ignore) {
                        string source = "p[" + i.ToString(CultureInfo.InvariantCulture) + "]";

                        string specifiedSource = null;
                        int specifiedPosition = 0;
                        if (member.CheckSpecified != SpecifiedAccessor.None) {
                            string memberNameSpecified = member.Name + "Specified";
                            for (int j = 0; j < mapping.Members.Length; j++) {
                                if (mapping.Members[j].Name == memberNameSpecified) {
                                    specifiedSource = "((bool) p[" + j.ToString(CultureInfo.InvariantCulture) + "])";
                                    specifiedPosition = j;
                                    break;
                                }
                            }
                        }

                        Writer.Write("if (pLength > ");
                        Writer.Write(i.ToString(CultureInfo.InvariantCulture));
                        Writer.WriteLine(") {");
                        Writer.Indent++;

                        if (specifiedSource != null) {
                            Writer.Write("if (pLength <= ");
                            Writer.Write(specifiedPosition.ToString(CultureInfo.InvariantCulture));
                            Writer.Write(" || ");
                            Writer.Write(specifiedSource);
                            Writer.WriteLine(") {");
                            Writer.Indent++;
                        }

                        WriteMember(source, member.Attribute, member.TypeDesc, "p");

                        if (specifiedSource != null) {
                            Writer.Indent--;
                            Writer.WriteLine("}");
                        }
                        
                        Writer.Indent--;
                        Writer.WriteLine("}");
                    }
                }
            }
               
            for (int i = 0; i < mapping.Members.Length; i++) {
                MemberMapping member = mapping.Members[i];
                if (member.Xmlns != null)
                    continue;
                if (member.Ignore)
                    continue;
                    
                string specifiedSource = null;
                int specifiedPosition = 0;
                if (member.CheckSpecified != SpecifiedAccessor.None) {
                    string memberNameSpecified = member.Name + "Specified";

                    for (int j = 0; j < mapping.Members.Length; j++) {
                        if (mapping.Members[j].Name == memberNameSpecified) {
                            specifiedSource = "((bool) p[" + j.ToString(CultureInfo.InvariantCulture) + "])";
                            specifiedPosition = j;
                            break;
                        }
                    }
                }

                Writer.Write("if (pLength > ");
                Writer.Write(i.ToString(CultureInfo.InvariantCulture));
                Writer.WriteLine(") {");
                Writer.Indent++;
               
                if (specifiedSource != null) {
                    Writer.Write("if (pLength <= ");
                    Writer.Write(specifiedPosition.ToString(CultureInfo.InvariantCulture));
                    Writer.Write(" || ");
                    Writer.Write(specifiedSource);
                    Writer.WriteLine(") {");
                    Writer.Indent++;
                }

                string source = "p[" + i.ToString(CultureInfo.InvariantCulture) + "]";
                string enumSource = null;
                if (member.ChoiceIdentifier != null) {
                    for (int j = 0; j < mapping.Members.Length; j++) {
                        if (mapping.Members[j].Name == member.ChoiceIdentifier.MemberName) {
                            if (member.ChoiceIdentifier.Mapping.TypeDesc.UseReflection)
                                enumSource = "p[" + j.ToString(CultureInfo.InvariantCulture) + "]";
                            else
                                enumSource = "((" + mapping.Members[j].TypeDesc.CSharpName + ")p[" + j.ToString(CultureInfo.InvariantCulture) + "]" + ")";
                            break;
                        }
                    }

                    #if DEBUG
                        // use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
                        if (enumSource == null) throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorDetails, "Can not find " + member.ChoiceIdentifier.MemberName + " in the members mapping."));
                    #endif

                }
                
                if (isRpc && member.IsReturnValue && member.Elements.Length > 0) {
                    Writer.Write("WriteRpcResult(");
                    WriteQuotedCSharpString(member.Elements[0].Name);
                    Writer.Write(", ");
                    WriteQuotedCSharpString("");
                    Writer.WriteLine(");");
                }

                // override writeAccessors choice when we've written a wrapper element
                WriteMember(source, enumSource, member.ElementsSortedByDerivation, member.Text, member.ChoiceIdentifier, member.TypeDesc, writeAccessors || hasWrapperElement);

                if (specifiedSource != null) {
                    Writer.Indent--;
                    Writer.WriteLine("}");
                }
                
                Writer.Indent--;
                Writer.WriteLine("}");
            }

            if (hasWrapperElement) {
                WriteEndElement();
            }
            if (element.IsSoap) {
                if (!hasWrapperElement && !writeAccessors) {
                    // doc/bare case -- allow extra members
                    Writer.Write("if (pLength > ");
                    Writer.Write(mapping.Members.Length.ToString(CultureInfo.InvariantCulture));
                    Writer.WriteLine(") {");
                    Writer.Indent++;
                    
                    WriteExtraMembers(mapping.Members.Length.ToString(CultureInfo.InvariantCulture), "pLength");
                
                    Writer.Indent--;
                    Writer.WriteLine("}");
                }
                Writer.WriteLine("WriteReferencedElements();");
            }
            Writer.Indent--;
            Writer.WriteLine("}");
            return methodName;
        }
 public XmlQualifiedName ExportTypeMapping(XmlMembersMapping xmlMembersMapping)
 {
     xmlMembersMapping.CheckShallow();
     this.CheckScope(xmlMembersMapping.Scope);
     MembersMapping mapping = (MembersMapping) xmlMembersMapping.Accessor.Mapping;
     if ((mapping.Members.Length != 1) || !(mapping.Members[0].Elements[0].Mapping is SpecialMapping))
     {
         return null;
     }
     SpecialMapping mapping2 = (SpecialMapping) mapping.Members[0].Elements[0].Mapping;
     XmlSchemaType item = this.ExportSpecialMapping(mapping2, xmlMembersMapping.Accessor.Namespace, false, null);
     if (((item != null) && (item.Name != null)) && (item.Name.Length > 0))
     {
         item.Name = xmlMembersMapping.Accessor.Name;
         this.AddSchemaItem(item, xmlMembersMapping.Accessor.Namespace, null);
     }
     this.ExportRootIfNecessary(xmlMembersMapping.Scope);
     return new XmlQualifiedName(xmlMembersMapping.Accessor.Name, xmlMembersMapping.Accessor.Namespace);
 }