private MessagePartDescriptionCollection GetWrappedParts(MessagePartDescription bodyPart)
                {
                    System.Type type = bodyPart.Type;
                    MessagePartDescriptionCollection descriptions = new MessagePartDescriptionCollection();

                    foreach (MemberInfo info in type.GetMembers(BindingFlags.Public | BindingFlags.Instance))
                    {
                        if (((info.MemberType & (MemberTypes.Property | MemberTypes.Field)) != 0) && !info.IsDefined(typeof(SoapIgnoreAttribute), false))
                        {
                            MessagePartDescription description;
                            System.ServiceModel.Description.XmlName name = new System.ServiceModel.Description.XmlName(info.Name);
                            description = new MessagePartDescription(name.EncodedName, string.Empty)
                            {
                                AdditionalAttributesProvider = description.MemberInfo = info,
                                Index = description.SerializationPosition = descriptions.Count,
                                Type  = (info.MemberType == MemberTypes.Property) ? ((PropertyInfo)info).PropertyType : ((FieldInfo)info).FieldType
                            };
                            if (bodyPart.HasProtectionLevel)
                            {
                                description.ProtectionLevel = bodyPart.ProtectionLevel;
                            }
                            descriptions.Add(description);
                        }
                    }
                    return(descriptions);
                }
        /// <summary>
        /// Copies the elements of the collection to an <see cref="Array"/>, starting at a particular array index.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the elements copied from collection. The array must have zero-based indexing.</param>
        /// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param>
        public void CopyTo(HttpParameterDescription[] array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            if (arrayIndex < 0 || ((arrayIndex + this.Count) > array.Length))
            {
                throw new ArgumentOutOfRangeException("arrayIndex");
            }

            if (this.IsSynchronized)
            {
                MessagePartDescriptionCollection mdpColl = this.MessagePartDescriptionCollection;
                if (mdpColl != null)
                {
                    HttpParameterDescription[] newArray = ToArray(mdpColl);
                    Array.Copy(newArray, 0, array, arrayIndex, newArray.Length);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("arrayIndex");
                }
            }
            else
            {
                this.innerCollection.CopyTo(array, arrayIndex);
            }
        }
Example #3
0
 internal MessageBodyDescription(MessageBodyDescription other)
 {
     this.WrapperName      = other.WrapperName;
     this.WrapperNamespace = other.WrapperNamespace;
     _parts = new MessagePartDescriptionCollection();
     foreach (MessagePartDescription mpd in other.Parts)
     {
         this.Parts.Add(mpd.Clone());
     }
     if (other.ReturnValue != null)
     {
         this.ReturnValue = other.ReturnValue.Clone();
     }
 }
 /// <summary>
 /// Removes all items from the collection.
 /// </summary>
 public void Clear()
 {
     if (this.IsSynchronized)
     {
         MessagePartDescriptionCollection mpdColl = this.MessagePartDescriptionCollection;
         if (mpdColl != null)
         {
             mpdColl.Clear();
         }
     }
     else
     {
         this.innerCollection.Clear();
     }
 }
        /// <summary>
        /// Returns an enumerator that iterates through the collection.
        /// </summary>
        /// <returns>An enumerator that can be used to iterate through the collection.</returns>
        Collections.IEnumerator Collections.IEnumerable.GetEnumerator()
        {
            if (this.IsSynchronized)
            {
                MessagePartDescriptionCollection mdpColl = this.MessagePartDescriptionCollection;
                if (mdpColl == null)
                {
                    return(Enumerable.Empty <HttpParameterDescription>().GetEnumerator());
                }

                HttpParameterDescription[] newArray = ToArray(mdpColl);
                return(newArray.GetEnumerator());
            }

            return(this.innerCollection.GetEnumerator());
        }
        /// <summary>
        /// Gets or sets the element at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the element to get or set.</param>
        /// <returns>The item at the specified index.</returns>
        public HttpParameterDescription this[int index]
        {
            get
            {
                if (index < 0 || (index >= this.Count))
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                if (this.IsSynchronized)
                {
                    // The Count check above will have thrown if there is no MessagePartDescriptionCollection,
                    // because Count would have been zero.
                    MessagePartDescriptionCollection mpdColl = this.MessagePartDescriptionCollection;
                    Debug.Assert(mpdColl != null, "MessagePartDescriptionCollection cannot be null");
                    return(new HttpParameterDescription(mpdColl[index]));
                }

                return(this.innerCollection[index]);
            }

            set
            {
                if (index < 0 || (index >= this.Count))
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }

                if (this.innerCollection != null)
                {
                    this.innerCollection[index] = value;
                }
                else
                {
                    // The Count check above will have thrown if there is no MessagePartDescriptionCollection,
                    // because Count would have been zero.
                    MessagePartDescriptionCollection mpdColl = this.MessagePartDescriptionCollection;
                    Debug.Assert(mpdColl != null, "MessagePartDescriptionCollection cannot be null");
                    mpdColl[index] = this.EnsureSynchronizedMessagePartDescription(value);
                }
            }
        }
        /// <summary>
        /// Adds an item to the collection.
        /// </summary>
        /// <param name="item">The object to add to the collection.</param>
        public void Add(HttpParameterDescription item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (this.IsSynchronized)
            {
                MessagePartDescription           mpd     = this.EnsureSynchronizedMessagePartDescription(item);
                MessagePartDescriptionCollection mpdColl = this.GetOrCreateMessagePartDescriptionCollection();
                mpdColl.Add(mpd);
            }
            else
            {
                this.innerCollection.Add(item);
            }
        }
        /// <summary>
        /// Removes the item at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the item to remove,</param>
        public void RemoveAt(int index)
        {
            if (index < 0 || (index >= this.Count))
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (this.IsSynchronized)
            {
                // The Count check above will have thrown if there is no MessagePartDescriptionCollection,
                // because Count would have been zero.
                MessagePartDescriptionCollection mpdColl = this.MessagePartDescriptionCollection;
                Debug.Assert(mpdColl != null, "MessagePartDescriptionCollection cannot be null");
                mpdColl.RemoveAt(index);
            }
            else
            {
                this.innerCollection.RemoveAt(index);
            }
        }
        /// <summary>
        /// Determines the index of a specific item in the collection.
        /// </summary>
        /// <param name="item">The object to locate in the collection.</param>
        /// <returns>The index of item if found in the list; otherwise, -1.</returns>
        public int IndexOf(HttpParameterDescription item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (this.IsSynchronized)
            {
                MessagePartDescriptionCollection mpdColl = this.MessagePartDescriptionCollection;
                if (mpdColl == null)
                {
                    return(-1);
                }

                MessagePartDescription mpd = this.EnsureSynchronizedMessagePartDescription(item);
                return(mpdColl.IndexOf(mpd));
            }

            return(this.innerCollection.IndexOf(item));
        }
        /// <summary>
        /// Removes the first occurrence of a specific object from the collection.
        /// </summary>
        /// <param name="item">The object to remove from the collection.</param>
        /// <returns><c>true</c> if <paramref name="item"/> was successfully removed from the collection; otherwise, <c>false</c>.
        /// This method also returns <c>false</c> if <paramref name="item"/> is not found in the original collection.</returns>
        public bool Remove(HttpParameterDescription item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (this.IsSynchronized)
            {
                MessagePartDescriptionCollection mdpColl = this.MessagePartDescriptionCollection;
                if (mdpColl == null)
                {
                    return(false);
                }

                MessagePartDescription mpd = this.EnsureSynchronizedMessagePartDescription(item);
                return(mdpColl.Remove(mpd));
            }

            return(this.innerCollection.Remove(item));
        }
        /// <summary>
        /// Retrieves the appropriate <see cref="MessagePartDescriptionCollection"/> for the current instance.
        /// If the synchronized <see cref="OperationDescription"/> does not have the corresponding collection,
        /// this method will create a default <see cref="MessageDescription"/> element so that the collection exists.
        /// </summary>
        /// <returns>The <see cref="MessagePartDescriptionCollection"/>.</returns>
        private MessagePartDescriptionCollection GetOrCreateMessagePartDescriptionCollection()
        {
            Debug.Assert(this.IsSynchronized, "This method cannot be called for unsynchronized collections");
            MessagePartDescriptionCollection mpdColl = this.MessagePartDescriptionCollection;

            if (mpdColl == null)
            {
                OperationDescription od = this.operationDescription;
                int messageIndex        = this.isOutputCollection ? 1 : 0;
                if (od.Messages.Count <= messageIndex)
                {
                    HttpOperationDescription.CreateMessageDescriptionIfNecessary(od, messageIndex);
                }

                Debug.Assert(od.Messages.Count > messageIndex, "CreateMessageDescription should have created Message element");
                mpdColl = od.Messages[messageIndex].Body.Parts;
            }

            Debug.Assert(mpdColl != null, "return value can never be null");
            return(mpdColl);
        }
        private CodeExpression[] ExportMessages(MessageDescriptionCollection messages, CodeMemberMethod method, bool return_args)
        {
            CodeExpression [] args = null;
            foreach (MessageDescription md in messages)
            {
                if (md.Direction == MessageDirection.Output)
                {
                    if (md.Body.ReturnValue != null)
                    {
                        ExportDataContract(md.Body.ReturnValue);
                        method.ReturnType = md.Body.ReturnValue.CodeTypeReference;
                    }
                    continue;
                }

                if (return_args)
                {
                    args = new CodeExpression [md.Body.Parts.Count];
                }

                MessagePartDescriptionCollection parts = md.Body.Parts;
                for (int i = 0; i < parts.Count; i++)
                {
                    ExportDataContract(parts [i]);

                    method.Parameters.Add(
                        new CodeParameterDeclarationExpression(
                            parts [i].CodeTypeReference,
                            parts [i].Name));

                    if (return_args)
                    {
                        args [i] = new CodeArgumentReferenceExpression(parts [i].Name);
                    }
                }
            }

            return(args);
        }
        /// <summary>
        /// Determines whether the collection contains a specific value.
        /// </summary>
        /// <param name="item">The object to locate in the collection.</param>
        /// <returns><c>true</c> if item is found in the collection; otherwise, <c>false</c>.</returns>
        public bool Contains(HttpParameterDescription item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (this.IsSynchronized)
            {
                MessagePartDescriptionCollection mdpColl = this.MessagePartDescriptionCollection;
                if (mdpColl == null)
                {
                    return(false);
                }

                // Strategy: use the knowledge we would have wrapped the MessagePartDescription in the
                // past when we released this HttpParameterDescription.
                MessagePartDescription mpd = this.EnsureSynchronizedMessagePartDescription(item);
                return(mdpColl.Contains(mpd));
            }

            return(this.innerCollection.Contains(item));
        }
        /// <summary>
        /// Inserts an item at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which item should be inserted.</param>
        /// <param name="item">The object to insert at the specified index.</param>
        public void Insert(int index, HttpParameterDescription item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (index < 0 || (index > this.Count))
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (this.IsSynchronized)
            {
                MessagePartDescription           mpd     = this.EnsureSynchronizedMessagePartDescription(item);
                MessagePartDescriptionCollection mpdColl = this.GetOrCreateMessagePartDescriptionCollection();
                Debug.Assert(mpdColl != null, "MessagePartDescriptionCollection cannot be null");
                mpdColl.Insert(index, mpd);
            }
            else
            {
                this.innerCollection.Insert(index, item);
            }
        }
Example #15
0
 public MessageBodyDescription()
 {
     _parts = new MessagePartDescriptionCollection();
 }
Example #16
0
                private XmlMembersMapping LoadBodyMapping(MessageDescription message, string mappingKey, out MessagePartDescriptionCollection rpcEncodedTypedMessageBodyParts)
                {
                    MessagePartDescription returnPart;
                    string wrapperName, wrapperNs;
                    MessagePartDescriptionCollection bodyParts;

                    rpcEncodedTypedMessageBodyParts = null;
                    returnPart  = OperationFormatter.IsValidReturnValue(message.Body.ReturnValue) ? message.Body.ReturnValue : null;
                    bodyParts   = message.Body.Parts;
                    wrapperName = message.Body.WrapperName;
                    wrapperNs   = message.Body.WrapperNamespace;
                    bool isWrapped      = (wrapperName != null);
                    bool hasReturnValue = returnPart != null;
                    int  paramCount     = bodyParts.Count + (hasReturnValue ? 1 : 0);

                    if (paramCount == 0 && !isWrapped) // no need to create serializer
                    {
                        return(null);
                    }

                    XmlReflectionMember[] members = new XmlReflectionMember[paramCount];
                    int paramIndex = 0;

                    if (hasReturnValue)
                    {
                        members[paramIndex++] = XmlSerializerHelper.GetXmlReflectionMember(returnPart, IsRpc, isWrapped);
                    }

                    for (int i = 0; i < bodyParts.Count; i++)
                    {
                        members[paramIndex++] = XmlSerializerHelper.GetXmlReflectionMember(bodyParts[i], IsRpc, isWrapped);
                    }

                    if (!isWrapped)
                    {
                        wrapperNs = ContractNamespace;
                    }
                    return(ImportMembersMapping(wrapperName, wrapperNs, members, isWrapped, IsRpc, mappingKey));
                }
 /// <summary>
 /// Creates an array of <see cref="HttpParameterDescription"/> elements that are synchronized with their
 /// corresponding <see cref="MessagePartDescription"/> elements.
 /// </summary>
 /// <param name="messagePartDescriptionCollection">The existing collection from which to create the array.</param>
 /// <returns>The new array.</returns>
 private static HttpParameterDescription[] ToArray(MessagePartDescriptionCollection messagePartDescriptionCollection)
 {
     return(messagePartDescriptionCollection
            .Select <MessagePartDescription, HttpParameterDescription>(m => new HttpParameterDescription(m))
            .ToArray());
 }
Example #18
0
 internal void SetBody(SerializerStub body, MessagePartDescriptionCollection rpcEncodedTypedMessageBodyParts)
 {
     _body = body;
     _rpcEncodedTypedMessageBodyParts = rpcEncodedTypedMessageBodyParts;
 }
 internal void SetBody(XmlSerializerOperationBehavior.Reflector.SerializerStub body, MessagePartDescriptionCollection rpcEncodedTypedMessageBodyParts)
 {
     this.body = body;
     this.rpcEncodedTypedMessageBodyParts = rpcEncodedTypedMessageBodyParts;
 }
                private XmlMembersMapping LoadBodyMapping(MessageDescription message, string mappingKey, out MessagePartDescriptionCollection rpcEncodedTypedMessageBodyParts)
                {
                    MessagePartDescription description;
                    string name;
                    string wrapperNamespace;
                    MessagePartDescriptionCollection parts;

                    if ((this.IsEncoded && message.IsTypedMessage) && (message.Body.WrapperName == null))
                    {
                        MessagePartDescription wrapperPart = this.GetWrapperPart(message);
                        description = null;
                        rpcEncodedTypedMessageBodyParts = parts = this.GetWrappedParts(wrapperPart);
                        name             = wrapperPart.Name;
                        wrapperNamespace = wrapperPart.Namespace;
                    }
                    else
                    {
                        rpcEncodedTypedMessageBodyParts = null;
                        description      = OperationFormatter.IsValidReturnValue(message.Body.ReturnValue) ? message.Body.ReturnValue : null;
                        parts            = message.Body.Parts;
                        name             = message.Body.WrapperName;
                        wrapperNamespace = message.Body.WrapperNamespace;
                    }
                    bool isWrapped = name != null;
                    bool flag2     = description != null;
                    int  num       = parts.Count + (flag2 ? 1 : 0);

                    if ((num == 0) && !isWrapped)
                    {
                        return(null);
                    }
                    XmlReflectionMember[] members = new XmlReflectionMember[num];
                    int num2 = 0;

                    if (flag2)
                    {
                        members[num2++] = XmlSerializerHelper.GetXmlReflectionMember(description, this.IsRpc, this.IsEncoded, isWrapped);
                    }
                    for (int i = 0; i < parts.Count; i++)
                    {
                        members[num2++] = XmlSerializerHelper.GetXmlReflectionMember(parts[i], this.IsRpc, this.IsEncoded, isWrapped);
                    }
                    if (!isWrapped)
                    {
                        wrapperNamespace = this.ContractNamespace;
                    }
                    return(this.ImportMembersMapping(name, wrapperNamespace, members, isWrapped, this.IsRpc, mappingKey));
                }