예제 #1
0
            internal object GetContentAndSaveHeaderAttributes(object parameterValue, MessageHeaderDescription headerDescription)
            {
                bool   flag;
                bool   flag2;
                string str;

                if (parameterValue == null)
                {
                    return(null);
                }
                if (headerDescription.Multiple)
                {
                    object[] objArray = (object[])parameterValue;
                    MessageHeader <object>[] headerArray = new MessageHeader <object> [objArray.Length];
                    Array array = Array.CreateInstance(headerDescription.Type, objArray.Length);
                    for (int i = 0; i < array.Length; i++)
                    {
                        array.SetValue(OperationFormatter.GetContentOfMessageHeaderOfT(headerDescription, objArray[i], out flag, out flag2, out str), i);
                        headerArray[i] = new MessageHeader <object>(null, flag, str, flag2);
                    }
                    this.attributes[headerDescription.Index] = headerArray;
                    return(array);
                }
                object obj2 = OperationFormatter.GetContentOfMessageHeaderOfT(headerDescription, parameterValue, out flag, out flag2, out str);

                this.attributes[headerDescription.Index] = new MessageHeader <object>(null, flag, str, flag2);
                return(obj2);
            }
예제 #2
0
        private void AddMessageHeaderForParameter(MessageHeaders headers, PartInfo headerPart, MessageVersion messageVersion, object parameterValue, bool isXmlElement)
        {
            string str;
            bool   flag;
            bool   flag2;
            MessageHeaderDescription headerDescription = (MessageHeaderDescription)headerPart.Description;
            object headerValue = OperationFormatter.GetContentOfMessageHeaderOfT(headerDescription, parameterValue, out flag, out flag2, out str);

            if (isXmlElement)
            {
                if (headerValue != null)
                {
                    XmlElement element = (XmlElement)headerValue;
                    headers.Add(new OperationFormatter.XmlElementMessageHeader(this, messageVersion, element.LocalName, element.NamespaceURI, flag, str, flag2, element));
                }
            }
            else
            {
                headers.Add(new DataContractSerializerMessageHeader(headerPart, headerValue, flag, str, flag2));
            }
        }
예제 #3
0
 protected override void AddHeadersToMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
 {
     try
     {
         XmlSerializer headerSerializer;
         OperationFormatter.MessageHeaderDescriptionTable headerDescriptionTable;
         MessageHeaderDescription unknownHeaderDescription;
         bool   mustUnderstand;
         bool   relay;
         string actor;
         if (isRequest)
         {
             headerSerializer         = this.requestMessageInfo.HeaderSerializer;
             headerDescriptionTable   = this.requestMessageInfo.HeaderDescriptionTable;
             unknownHeaderDescription = this.requestMessageInfo.UnknownHeaderDescription;
         }
         else
         {
             headerSerializer         = this.replyMessageInfo.HeaderSerializer;
             headerDescriptionTable   = this.replyMessageInfo.HeaderDescriptionTable;
             unknownHeaderDescription = this.replyMessageInfo.UnknownHeaderDescription;
         }
         if (headerSerializer != null)
         {
             object[] o = new object[headerDescriptionTable.Count];
             MessageHeaderOfTHelper helper = null;
             int num = 0;
             foreach (MessageHeaderDescription description2 in messageDescription.Headers)
             {
                 object obj2 = parameters[description2.Index];
                 if (!description2.IsUnknownHeaderCollection)
                 {
                     if (description2.TypedHeader)
                     {
                         if (helper == null)
                         {
                             helper = new MessageHeaderOfTHelper(parameters.Length);
                         }
                         o[num++] = helper.GetContentAndSaveHeaderAttributes(parameters[description2.Index], description2);
                     }
                     else
                     {
                         o[num++] = obj2;
                     }
                 }
             }
             MemoryStream        stream    = new MemoryStream();
             XmlDictionaryWriter xmlWriter = XmlDictionaryWriter.CreateTextWriter(stream);
             xmlWriter.WriteStartElement("root");
             headerSerializer.Serialize(xmlWriter, o, null, this.isEncoded ? GetEncoding(message.Version.Envelope) : null);
             xmlWriter.WriteEndElement();
             xmlWriter.Flush();
             XmlDocument document = new XmlDocument();
             stream.Position = 0L;
             document.Load(stream);
             foreach (XmlElement element in document.DocumentElement.ChildNodes)
             {
                 MessageHeaderDescription headerDescription = headerDescriptionTable.Get(element.LocalName, element.NamespaceURI);
                 if (headerDescription == null)
                 {
                     message.Headers.Add(new OperationFormatter.XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI, false, null, false, element));
                 }
                 else
                 {
                     if (headerDescription.TypedHeader)
                     {
                         helper.GetHeaderAttributes(headerDescription, out mustUnderstand, out relay, out actor);
                     }
                     else
                     {
                         mustUnderstand = headerDescription.MustUnderstand;
                         relay          = headerDescription.Relay;
                         actor          = headerDescription.Actor;
                     }
                     message.Headers.Add(new OperationFormatter.XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI, mustUnderstand, actor, relay, element));
                 }
             }
         }
         if ((unknownHeaderDescription != null) && (parameters[unknownHeaderDescription.Index] != null))
         {
             foreach (object obj3 in (IEnumerable)parameters[unknownHeaderDescription.Index])
             {
                 XmlElement headerValue = (XmlElement)OperationFormatter.GetContentOfMessageHeaderOfT(unknownHeaderDescription, obj3, out mustUnderstand, out relay, out actor);
                 if (headerValue != null)
                 {
                     message.Headers.Add(new OperationFormatter.XmlElementMessageHeader(this, message.Version, headerValue.LocalName, headerValue.NamespaceURI, mustUnderstand, actor, relay, headerValue));
                 }
             }
         }
     }
     catch (InvalidOperationException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SFxErrorSerializingHeader", new object[] { messageDescription.MessageName, exception.Message }), exception));
     }
 }