Beispiel #1
0
            internal void GetHeaderAttributes(MessageHeaderDescription headerDescription, out bool mustUnderstand, out bool relay, out string actor)
            {
                MessageHeader <object> header = null;

                if (headerDescription.Multiple)
                {
                    MessageHeader <object>[] headerArray = (MessageHeader <object>[]) this.attributes[headerDescription.Index];
                    for (int i = 0; i < headerArray.Length; i++)
                    {
                        if (headerArray[i] != null)
                        {
                            header         = headerArray[i];
                            headerArray[i] = null;
                            break;
                        }
                    }
                }
                else
                {
                    header = (MessageHeader <object>) this.attributes[headerDescription.Index];
                }
                mustUnderstand = header.MustUnderstand;
                relay          = header.Relay;
                actor          = header.Actor;
            }
Beispiel #2
0
            internal object GetContentAndSaveHeaderAttributes(object parameterValue, MessageHeaderDescription headerDescription)
            {
                if (parameterValue == null)
                {
                    return(null);
                }

                bool   mustUnderstand;
                bool   relay;
                string actor;

                if (headerDescription.Multiple)
                {
                    object[] messageHeaderOfTArray = (object[])parameterValue;
                    MessageHeader <object>[] messageHeaderOfTAttributes = new MessageHeader <object> [messageHeaderOfTArray.Length];
                    Array tArray = Array.CreateInstance(headerDescription.Type, messageHeaderOfTArray.Length);
                    for (int i = 0; i < tArray.Length; i++)
                    {
                        tArray.SetValue(GetContentOfMessageHeaderOfT(headerDescription, messageHeaderOfTArray[i], out mustUnderstand, out relay, out actor), i);
                        messageHeaderOfTAttributes[i] = new MessageHeader <object>(null, mustUnderstand, actor, relay);
                    }
                    _attributes[headerDescription.Index] = messageHeaderOfTAttributes;
                    return(tArray);
                }
                else
                {
                    object content = GetContentOfMessageHeaderOfT(headerDescription, parameterValue, out mustUnderstand, out relay, out actor);
                    _attributes[headerDescription.Index] = new MessageHeader <object>(null, mustUnderstand, actor, relay);
                    return(content);
                }
            }
Beispiel #3
0
            internal void GetHeaderAttributes(MessageHeaderDescription headerDescription, out bool mustUnderstand, out bool relay, out string actor)
            {
                MessageHeader <object> matchingMessageHeaderOfTAttribute = null;

                if (headerDescription.Multiple)
                {
                    MessageHeader <object>[] messageHeaderOfTAttributes = (MessageHeader <object>[])_attributes[headerDescription.Index];
                    for (int i = 0; i < messageHeaderOfTAttributes.Length; i++)
                    {
                        if (messageHeaderOfTAttributes[i] != null)
                        {
                            matchingMessageHeaderOfTAttribute = messageHeaderOfTAttributes[i];
                            messageHeaderOfTAttributes[i]     = null;
                            break;
                        }
                    }
                    //assert(matchingMessageHeaderOfTAttribute != null);
                }
                else
                {
                    matchingMessageHeaderOfTAttribute = (MessageHeader <object>)_attributes[headerDescription.Index];
                }

                mustUnderstand = matchingMessageHeaderOfTAttribute.MustUnderstand;
                relay          = matchingMessageHeaderOfTAttribute.Relay;
                actor          = matchingMessageHeaderOfTAttribute.Actor;
            }
Beispiel #4
0
        protected override void AddHeadersToMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            MessageInfo info = isRequest ? this.requestMessageInfo : this.replyMessageInfo;

            PartInfo[] headerParts = info.HeaderParts;
            if ((headerParts != null) && (headerParts.Length != 0))
            {
                MessageHeaders headers = message.Headers;
                for (int i = 0; i < headerParts.Length; i++)
                {
                    PartInfo headerPart = headerParts[i];
                    MessageHeaderDescription description = (MessageHeaderDescription)headerPart.Description;
                    object parameterValue = parameters[description.Index];
                    if (description.Multiple)
                    {
                        if (parameterValue != null)
                        {
                            bool isXmlElement = description.Type == typeof(XmlElement);
                            foreach (object obj3 in (IEnumerable)parameterValue)
                            {
                                this.AddMessageHeaderForParameter(headers, headerPart, message.Version, obj3, isXmlElement);
                            }
                        }
                    }
                    else
                    {
                        this.AddMessageHeaderForParameter(headers, headerPart, message.Version, parameterValue, false);
                    }
                }
            }
        }
        protected override void AddHeadersToMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            MessageInfo messageInfo = isRequest ? requestMessageInfo : replyMessageInfo;

            PartInfo[] headerParts = messageInfo.HeaderParts;
            if (headerParts == null || headerParts.Length == 0)
            {
                return;
            }

            MessageHeaders headers = message.Headers;

            for (int i = 0; i < headerParts.Length; i++)
            {
                PartInfo headerPart = headerParts[i];
                MessageHeaderDescription headerDescription = (MessageHeaderDescription)headerPart.Description;
                object headerValue = parameters[headerDescription.Index];

                if (headerDescription.Multiple)
                {
                    if (headerValue != null)
                    {
                        bool isXmlElement = headerDescription.Type == typeof(XmlElement);
                        foreach (object headerItemValue in (IEnumerable)headerValue)
                        {
                            AddMessageHeaderForParameter(headers, headerPart, message.Version, headerItemValue, isXmlElement);
                        }
                    }
                }
                else
                {
                    AddMessageHeaderForParameter(headers, headerPart, message.Version, headerValue, false /*isXmlElement*/);
                }
            }
        }
Beispiel #6
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);
            }
 // Methods
 internal MessageHeaderDescription(MessageHeaderDescription other) : base(other)
 {
     this.MustUnderstand = other.MustUnderstand;
     this.Relay = other.Relay;
     this.Actor = other.Actor;
     this.TypedHeader = other.TypedHeader;
     this.IsUnknownHeaderCollection = other.IsUnknownHeaderCollection;
 }
Beispiel #8
0
 internal static object GetContentOfMessageHeaderOfT(MessageHeaderDescription headerDescription, object parameterValue, out bool mustUnderstand, out bool relay, out string actor)
 {
     actor          = headerDescription.Actor;
     mustUnderstand = headerDescription.MustUnderstand;
     relay          = headerDescription.Relay;
     if (headerDescription.TypedHeader && (parameterValue != null))
     {
         parameterValue = TypedHeaderManager.GetContent(headerDescription.Type, parameterValue, out mustUnderstand, out relay, out actor);
     }
     return(parameterValue);
 }
Beispiel #9
0
        private static void AddHeaderProtectionRequirements(MessageHeaderDescription header, MessagePartSpecification signedParts, MessagePartSpecification encryptedParts, ProtectionLevel defaultProtectionLevel)
        {
            ProtectionLevel level = header.HasProtectionLevel ? header.ProtectionLevel : defaultProtectionLevel;

            if (level != ProtectionLevel.None)
            {
                XmlQualifiedName item = new XmlQualifiedName(header.Name, header.Namespace);
                signedParts.HeaderTypes.Add(item);
                if (level == ProtectionLevel.EncryptAndSign)
                {
                    encryptedParts.HeaderTypes.Add(item);
                }
            }
        }
Beispiel #10
0
        private static void AddUnknownHeader(MessageHeaderDescription unknownHeaderDescription, ArrayList unknownHeaders, XmlDocument xmlDoc, XmlDictionaryWriter bufferWriter, MessageHeaderInfo header, XmlDictionaryReader headerReader)
        {
            object content = xmlDoc.ReadNode(headerReader);

            if (bufferWriter != null)
            {
                ((XmlElement)content).WriteTo(bufferWriter);
            }
            if ((content != null) && unknownHeaderDescription.TypedHeader)
            {
                content = TypedHeaderManager.Create(unknownHeaderDescription.Type, content, header.MustUnderstand, header.Relay, header.Actor);
            }
            unknownHeaders.Add(content);
        }
        private MessageInfo CreateMessageInfo(DataContractFormatAttribute dataContractFormatAttribute,
                                              MessageDescription messageDescription, DataContractSerializerOperationBehavior serializerFactory)
        {
            if (messageDescription.IsUntypedMessage)
            {
                return(null);
            }

            MessageInfo messageInfo = new MessageInfo();

            MessageBodyDescription body = messageDescription.Body;

            if (body.WrapperName != null)
            {
                messageInfo.WrapperName      = AddToDictionary(body.WrapperName);
                messageInfo.WrapperNamespace = AddToDictionary(body.WrapperNamespace);
            }
            MessagePartDescriptionCollection parts = body.Parts;

            messageInfo.BodyParts = new PartInfo[parts.Count];
            for (int i = 0; i < parts.Count; i++)
            {
                messageInfo.BodyParts[i] = CreatePartInfo(parts[i], dataContractFormatAttribute.Style, serializerFactory);
            }

            if (IsValidReturnValue(messageDescription.Body.ReturnValue))
            {
                messageInfo.ReturnPart = CreatePartInfo(messageDescription.Body.ReturnValue, dataContractFormatAttribute.Style, serializerFactory);
            }

            messageInfo.HeaderDescriptionTable = new MessageHeaderDescriptionTable();
            messageInfo.HeaderParts            = new PartInfo[messageDescription.Headers.Count];
            for (int i = 0; i < messageDescription.Headers.Count; i++)
            {
                MessageHeaderDescription headerDescription = messageDescription.Headers[i];
                if (headerDescription.IsUnknownHeaderCollection)
                {
                    messageInfo.UnknownHeaderDescription = headerDescription;
                }
                else
                {
                    ValidateDataContractType(headerDescription.Type);
                    messageInfo.HeaderDescriptionTable.Add(headerDescription.Name, headerDescription.Namespace, headerDescription);
                }
                messageInfo.HeaderParts[i] = CreatePartInfo(headerDescription, OperationFormatStyle.Document, serializerFactory);
            }
            messageInfo.AnyHeaders = messageInfo.UnknownHeaderDescription != null || messageInfo.HeaderDescriptionTable.Count > 0;
            return(messageInfo);
        }
Beispiel #12
0
 internal void SetHeaderAttributes(MessageHeaderDescription headerDescription, bool mustUnderstand, bool relay, string actor)
 {
     if (headerDescription.Multiple)
     {
         if (this.attributes[headerDescription.Index] == null)
         {
             this.attributes[headerDescription.Index] = new List <MessageHeader <object> >();
         }
         ((List <MessageHeader <object> >) this.attributes[headerDescription.Index]).Add(new MessageHeader <object>(null, mustUnderstand, actor, relay));
     }
     else
     {
         this.attributes[headerDescription.Index] = new MessageHeader <object>(null, mustUnderstand, actor, relay);
     }
 }
        void IOperationContractGenerationExtension.GenerateOperation(OperationContractGenerationContext context)
        {
            foreach (KeyValuePair <MessageHeaderDescription, SoapHeaderDirection> pair in headers)
            {
                MessageHeaderDescription header = pair.Key;
                string headerTypeName           = (string)ReflectionUtils.GetValue(header, "BaseType");

                CodeAttributeArgument arg1 = new CodeAttributeArgument(new CodePrimitiveExpression(header.Name));
                CodeAttributeArgument arg2 = new CodeAttributeArgument(new CodeTypeOfExpression(headerTypeName));
                CodeAttributeArgument arg3 = new CodeAttributeArgument("Direction", new CodeFieldReferenceExpression(
                                                                           new CodeTypeReferenceExpression(typeof(SoapHeaderDirection)), pair.Value.ToString()));
                CodeAttributeDeclaration attrib = new CodeAttributeDeclaration(new CodeTypeReference(typeof(SoapHeaderAttribute)), arg1, arg2, arg3);
                context.SyncMethod.CustomAttributes.Add(attrib);
            }
        }
        void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
        {
            // Build the custom header description
            var headerDescription = new MessageHeaderDescription(CustomHeader.Name, CustomHeader.Namespace);

            headerDescription.Type = typeof(CustomHeader);

            // Loop through all the operations defined for the contract and add custom SOAP header to the WSDL
            foreach (OperationDescription op in context.Contract.Operations)
            {
                foreach (MessageDescription messageDescription in op.Messages)
                {
                    messageDescription.Headers.Add(headerDescription);
                }
            }
        }
Beispiel #15
0
        static void AddHeaderProtectionRequirements(MessageHeaderDescription header, MessagePartSpecification signedParts,
                                                    MessagePartSpecification encryptedParts, ProtectionLevel defaultProtectionLevel)
        {
            var p = defaultProtectionLevel; //header.HasProtectionLevel currently is always false;

            //ProtectionLevel p = header.HasProtectionLevel ? header.ProtectionLevel : defaultProtectionLevel;

            if (p != ProtectionLevel.None)
            {
                var headerName = new XmlQualifiedName(header.Name, header.Namespace);
                signedParts.HeaderTypes.Add(headerName);
                if (p == ProtectionLevel.EncryptAndSign)
                {
                    encryptedParts.HeaderTypes.Add(headerName);
                }
            }
        }
        internal static void AddSoapHeader(OperationDescription op, SoapHeaderAttribute soapHeader)
        {
            string headerNamespace          = SoapHeaderHelper.GetNamespace(soapHeader.Type);
            MessageHeaderDescription header = new MessageHeaderDescription(soapHeader.Name, headerNamespace);

            header.Type = soapHeader.Type;
            bool input  = ((soapHeader.Direction & SoapHeaderDirection.In) == SoapHeaderDirection.In);
            bool output = ((soapHeader.Direction & SoapHeaderDirection.Out) == SoapHeaderDirection.Out);

            foreach (MessageDescription msgDescription in op.Messages)
            {
                if ((msgDescription.Direction == MessageDirection.Input && input) ||
                    (msgDescription.Direction == MessageDirection.Output && output))
                {
                    msgDescription.Headers.Add(header);
                }
            }
        }
        private void AddMessageHeaderForParameter(MessageHeaders headers, PartInfo headerPart, MessageVersion messageVersion, object parameterValue, bool isXmlElement)
        {
            MessageHeaderDescription headerDescription = (MessageHeaderDescription)headerPart.Description;
            object valueToSerialize = GetContentOfMessageHeaderOfT(headerDescription, parameterValue, out bool mustUnderstand, out bool relay, out string actor);

            if (isXmlElement)
            {
                if (valueToSerialize == null)
                {
                    return;
                }

                XmlElement xmlElement = (XmlElement)valueToSerialize;
                headers.Add(new XmlElementMessageHeader(this, messageVersion, xmlElement.LocalName, xmlElement.NamespaceURI, mustUnderstand, actor, relay, xmlElement));
                return;
            }
            headers.Add(new DataContractSerializerMessageHeader(headerPart, valueToSerialize, mustUnderstand, actor, relay));
        }
Beispiel #18
0
            internal object CreateMessageHeader(MessageHeaderDescription headerDescription, object headerValue)
            {
                if (headerDescription.Multiple)
                {
                    IList <MessageHeader <object> > list = (IList <MessageHeader <object> >) this.attributes[headerDescription.Index];
                    object[] objArray = (object[])Array.CreateInstance(TypedHeaderManager.GetMessageHeaderType(headerDescription.Type), list.Count);
                    Array    array    = (Array)headerValue;
                    for (int i = 0; i < objArray.Length; i++)
                    {
                        MessageHeader <object> header = list[i];
                        objArray[i] = TypedHeaderManager.Create(headerDescription.Type, array.GetValue(i), header.MustUnderstand, header.Relay, header.Actor);
                    }
                    return(objArray);
                }
                MessageHeader <object> header2 = (MessageHeader <object>) this.attributes[headerDescription.Index];

                return(TypedHeaderManager.Create(headerDescription.Type, headerValue, header2.MustUnderstand, header2.Relay, header2.Actor));
            }
Beispiel #19
0
        private MessageInfo CreateMessageInfo(DataContractFormatAttribute dataContractFormatAttribute, MessageDescription messageDescription, DataContractSerializerOperationBehavior serializerFactory)
        {
            if (messageDescription.IsUntypedMessage)
            {
                return(null);
            }
            MessageInfo            info = new MessageInfo();
            MessageBodyDescription body = messageDescription.Body;

            if (body.WrapperName != null)
            {
                info.WrapperName      = base.AddToDictionary(body.WrapperName);
                info.WrapperNamespace = base.AddToDictionary(body.WrapperNamespace);
            }
            MessagePartDescriptionCollection parts = body.Parts;

            info.BodyParts = new PartInfo[parts.Count];
            for (int i = 0; i < parts.Count; i++)
            {
                info.BodyParts[i] = this.CreatePartInfo(parts[i], dataContractFormatAttribute.Style, serializerFactory);
            }
            if (OperationFormatter.IsValidReturnValue(messageDescription.Body.ReturnValue))
            {
                info.ReturnPart = this.CreatePartInfo(messageDescription.Body.ReturnValue, dataContractFormatAttribute.Style, serializerFactory);
            }
            info.HeaderDescriptionTable = new OperationFormatter.MessageHeaderDescriptionTable();
            info.HeaderParts            = new PartInfo[messageDescription.Headers.Count];
            for (int j = 0; j < messageDescription.Headers.Count; j++)
            {
                MessageHeaderDescription message = messageDescription.Headers[j];
                if (message.IsUnknownHeaderCollection)
                {
                    info.UnknownHeaderDescription = message;
                }
                else
                {
                    this.ValidateDataContractType(message.Type);
                    info.HeaderDescriptionTable.Add(message.Name, message.Namespace, message);
                }
                info.HeaderParts[j] = this.CreatePartInfo(message, OperationFormatStyle.Document, serializerFactory);
            }
            info.AnyHeaders = (info.UnknownHeaderDescription != null) || (info.HeaderDescriptionTable.Count > 0);
            return(info);
        }
Beispiel #20
0
        protected void AddMessageHeader(MessageDescription message, string headerNamespace, string headerName, Type headerType)
        {
            if (message != null)
            {
                MessageBodyDescription messageBody = message.Body;
                if (messageBody != null)
                {
                    if (headerNamespace.IsEmpty())
                    {
                        if (!messageBody.WrapperNamespace.IsEmpty())
                        {
                            headerNamespace = messageBody.WrapperNamespace;
                            if (!messageBody.WrapperName.IsEmpty())
                            {
                                headerNamespace += "." + messageBody.Parts[1].Name;
                            }
                        }
                        else if (messageBody.Parts != null && messageBody.Parts.Count > 0)
                        {
                            headerNamespace = messageBody.Parts[0].Namespace;
                        }
                    }

                    if (!headerNamespace.IsEmpty())
                    {
                        MessageHeaderDescription header = (from h in message.Headers.OfType <MessageHeaderDescription>()
                                                           where h.Name.IgnoreCaseCompare(headerName) &&
                                                           h.Namespace.IgnoreCaseCompare(headerNamespace)
                                                           select h).FirstOrDefault();
                        if (header == null)
                        {
                            header = new MessageHeaderDescription(headerName, headerNamespace);
                            header.MustUnderstand = true;
                            header.MemberInfo     = headerType;
                            header.Type           = headerType;
                            header.TypedHeader    = true;
                            message.Headers.Add(header);
                        }
                    }
                }
            }
        }
        public void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
        {
            // Build the custom header description
            var headerDescription = new MessageHeaderDescription(CustomHeader.Name, CustomHeader.Namespace);

            headerDescription.Type = typeof(CustomHeader);

            var headers = context.ContractConversionContext.Contract.Operations;

            // Loop through all the operations defined for the contract and add custom SOAP header to the WSDL
            //foreach (OperationDescription op in context.ContractConversionContext.Contract.Operations)
            //{
            //    foreach (MessageDescription messageDescription in op.Messages)
            //    {
            //       var exist =  messageDescription.Headers.Any(x => x.Equals(headerDescription));
            //       if(!exist)
            //          messageDescription.Headers.Add(headerDescription);
            //    }
            //}
        }
Beispiel #22
0
        static void AddPartProtectionRequirements(List <XmlQualifiedName> enc,
                                                  List <XmlQualifiedName> sig,
                                                  MessageHeaderDescription pd,
                                                  ChannelProtectionRequirements cp)
        {
            if (!pd.HasProtectionLevel)
            {
                return;                 // no specific part indication
            }
            switch (pd.ProtectionLevel)
            {
            case ProtectionLevel.EncryptAndSign:
                enc.Add(new XmlQualifiedName(pd.Name, pd.Namespace));
                goto case ProtectionLevel.Sign;

            case ProtectionLevel.Sign:
                sig.Add(new XmlQualifiedName(pd.Name, pd.Namespace));
                break;
            }
        }
Beispiel #23
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));
            }
        }
Beispiel #24
0
 internal object CreateMessageHeader(MessageHeaderDescription headerDescription, object headerValue)
 {
     if (headerDescription.Multiple)
     {
         IList <MessageHeader <object> > messageHeaderOfTAttributes = (IList <MessageHeader <object> >)_attributes[headerDescription.Index];
         object[] messageHeaderOfTArray = (object[])Array.CreateInstance(TypedHeaderManager.GetMessageHeaderType(headerDescription.Type), messageHeaderOfTAttributes.Count);
         Array    headerValues          = (Array)headerValue;
         for (int i = 0; i < messageHeaderOfTArray.Length; i++)
         {
             MessageHeader <object> messageHeaderOfTAttribute = messageHeaderOfTAttributes[i];
             messageHeaderOfTArray[i] = TypedHeaderManager.Create(headerDescription.Type, headerValues.GetValue(i),
                                                                  messageHeaderOfTAttribute.MustUnderstand, messageHeaderOfTAttribute.Relay, messageHeaderOfTAttribute.Actor);
         }
         return(messageHeaderOfTArray);
     }
     else
     {
         MessageHeader <object> messageHeaderOfTAttribute = (MessageHeader <object>)_attributes[headerDescription.Index];
         return(TypedHeaderManager.Create(headerDescription.Type, headerValue,
                                          messageHeaderOfTAttribute.MustUnderstand, messageHeaderOfTAttribute.Relay, messageHeaderOfTAttribute.Actor));
     }
 }
Beispiel #25
0
 protected override void GetHeadersFromMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
 {
     try
     {
         XmlSerializer headerSerializer;
         OperationFormatter.MessageHeaderDescriptionTable headerDescriptionTable;
         MessageHeaderDescription unknownHeaderDescription;
         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;
         }
         MessageHeaders headers        = message.Headers;
         ArrayList      unknownHeaders = null;
         XmlDocument    xmlDoc         = null;
         if (unknownHeaderDescription != null)
         {
             unknownHeaders = new ArrayList();
             xmlDoc         = new XmlDocument();
         }
         if (headerSerializer == null)
         {
             if (unknownHeaderDescription != null)
             {
                 for (int i = 0; i < headers.Count; i++)
                 {
                     AddUnknownHeader(unknownHeaderDescription, unknownHeaders, xmlDoc, null, headers[i], headers.GetReaderAtHeader(i));
                 }
                 parameters[unknownHeaderDescription.Index] = unknownHeaders.ToArray(unknownHeaderDescription.TypedHeader ? typeof(MessageHeader <XmlElement>) : typeof(XmlElement));
             }
         }
         else
         {
             MemoryStream        stream = new MemoryStream();
             XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream);
             message.WriteStartEnvelope(writer);
             message.WriteStartHeaders(writer);
             MessageHeaderOfTHelper helper = null;
             for (int j = 0; j < headers.Count; j++)
             {
                 MessageHeaderInfo        headerInfo        = headers[j];
                 XmlDictionaryReader      readerAtHeader    = headers.GetReaderAtHeader(j);
                 MessageHeaderDescription headerDescription = headerDescriptionTable.Get(headerInfo.Name, headerInfo.Namespace);
                 if (headerDescription != null)
                 {
                     if (headerInfo.MustUnderstand)
                     {
                         headers.UnderstoodHeaders.Add(headerInfo);
                     }
                     if (headerDescription.TypedHeader)
                     {
                         if (helper == null)
                         {
                             helper = new MessageHeaderOfTHelper(parameters.Length);
                         }
                         helper.SetHeaderAttributes(headerDescription, headerInfo.MustUnderstand, headerInfo.Relay, headerInfo.Actor);
                     }
                 }
                 if ((headerDescription == null) && (unknownHeaderDescription != null))
                 {
                     AddUnknownHeader(unknownHeaderDescription, unknownHeaders, xmlDoc, writer, headerInfo, readerAtHeader);
                 }
                 else
                 {
                     writer.WriteNode(readerAtHeader, false);
                 }
                 readerAtHeader.Close();
             }
             writer.WriteEndElement();
             writer.WriteEndElement();
             writer.Flush();
             stream.Position = 0L;
             XmlDictionaryReader xmlReader = XmlDictionaryReader.CreateTextReader(stream.GetBuffer(), 0, (int)stream.Length, XmlDictionaryReaderQuotas.Max);
             xmlReader.ReadStartElement();
             xmlReader.MoveToContent();
             if (!xmlReader.IsEmptyElement)
             {
                 xmlReader.ReadStartElement();
                 object[] objArray = (object[])headerSerializer.Deserialize(xmlReader, this.isEncoded ? GetEncoding(message.Version.Envelope) : null);
                 int      num3     = 0;
                 foreach (MessageHeaderDescription description3 in messageDescription.Headers)
                 {
                     if (!description3.IsUnknownHeaderCollection)
                     {
                         object headerValue = objArray[num3++];
                         if (description3.TypedHeader && (headerValue != null))
                         {
                             headerValue = helper.CreateMessageHeader(description3, headerValue);
                         }
                         parameters[description3.Index] = headerValue;
                     }
                 }
                 xmlReader.Close();
             }
             if (unknownHeaderDescription != null)
             {
                 parameters[unknownHeaderDescription.Index] = unknownHeaders.ToArray(unknownHeaderDescription.TypedHeader ? typeof(MessageHeader <XmlElement>) : typeof(XmlElement));
             }
         }
     }
     catch (InvalidOperationException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SFxErrorDeserializingHeader", new object[] { messageDescription.MessageName }), exception));
     }
 }
Beispiel #26
0
        protected override void AddHeadersToMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            XmlSerializer serializer;
            MessageHeaderDescriptionTable headerDescriptionTable;
            MessageHeaderDescription      unknownHeaderDescription;
            bool   mustUnderstand;
            bool   relay;
            string actor;

            try
            {
                if (isRequest)
                {
                    serializer               = _requestMessageInfo.HeaderSerializer;
                    headerDescriptionTable   = _requestMessageInfo.HeaderDescriptionTable;
                    unknownHeaderDescription = _requestMessageInfo.UnknownHeaderDescription;
                }
                else
                {
                    serializer               = _replyMessageInfo.HeaderSerializer;
                    headerDescriptionTable   = _replyMessageInfo.HeaderDescriptionTable;
                    unknownHeaderDescription = _replyMessageInfo.UnknownHeaderDescription;
                }
                if (serializer != null)
                {
                    object[] headerValues = new object[headerDescriptionTable.Count];
                    MessageHeaderOfTHelper messageHeaderOfTHelper = null;
                    int headerIndex = 0;

                    foreach (MessageHeaderDescription headerDescription in messageDescription.Headers)
                    {
                        object parameterValue = parameters[headerDescription.Index];
                        if (!headerDescription.IsUnknownHeaderCollection)
                        {
                            if (headerDescription.TypedHeader)
                            {
                                if (messageHeaderOfTHelper == null)
                                {
                                    messageHeaderOfTHelper = new MessageHeaderOfTHelper(parameters.Length);
                                }

                                headerValues[headerIndex++] = messageHeaderOfTHelper.GetContentAndSaveHeaderAttributes(parameters[headerDescription.Index], headerDescription);
                            }
                            else
                            {
                                headerValues[headerIndex++] = parameterValue;
                            }
                        }
                    }

                    MemoryStream        memoryStream = new MemoryStream();
                    XmlDictionaryWriter bufferWriter = XmlDictionaryWriter.CreateTextWriter(memoryStream);
                    bufferWriter.WriteStartElement("root");
                    serializer.Serialize(bufferWriter, headerValues, null, _isEncoded ? GetEncoding(message.Version.Envelope) : null);
                    bufferWriter.WriteEndElement();
                    bufferWriter.Flush();
                    XmlDocument doc = new XmlDocument();
                    memoryStream.Position = 0;
                    doc.Load(memoryStream);
                    foreach (XmlElement element in doc.DocumentElement.ChildNodes)
                    {
                        MessageHeaderDescription matchingHeaderDescription = headerDescriptionTable.Get(element.LocalName, element.NamespaceURI);
                        if (matchingHeaderDescription == null)
                        {
                            message.Headers.Add(new XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI,
                                                                            false /*mustUnderstand*/, null /*actor*/, false /*relay*/, element));
                        }
                        else
                        {
                            if (matchingHeaderDescription.TypedHeader)
                            {
                                messageHeaderOfTHelper.GetHeaderAttributes(matchingHeaderDescription, out mustUnderstand, out relay, out actor);
                            }
                            else
                            {
                                mustUnderstand = matchingHeaderDescription.MustUnderstand;
                                relay          = matchingHeaderDescription.Relay;
                                actor          = matchingHeaderDescription.Actor;
                            }
                            message.Headers.Add(new XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI,
                                                                            mustUnderstand, actor, relay, element));
                        }
                    }
                }
                if (unknownHeaderDescription != null && parameters[unknownHeaderDescription.Index] != null)
                {
                    foreach (object unknownHeader in (IEnumerable)parameters[unknownHeaderDescription.Index])
                    {
                        XmlElement element = (XmlElement)GetContentOfMessageHeaderOfT(unknownHeaderDescription, unknownHeader, out mustUnderstand, out relay, out actor);
                        if (element != null)
                        {
                            message.Headers.Add(new XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI,
                                                                            mustUnderstand, actor, relay, element));
                        }
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                              SR.Format(SR.SFxErrorSerializingHeader, messageDescription.MessageName, e.Message), e));
            }
        }
Beispiel #27
0
 MessageHeader CreateHeader(MessageHeaderDescription mh, object value)
 {
     return(MessageHeader.CreateHeader(mh.Name, mh.Namespace, value, mh.MustUnderstand, mh.Actor, mh.Relay));
 }
Beispiel #28
0
 public static string GetHeaderType(this MessageHeaderDescription header)
 {
     return((string)ReflectionUtils.GetValue(header, "BaseType"));
 }
        protected override void GetHeadersFromMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            MessageInfo messageInfo = isRequest ? requestMessageInfo : replyMessageInfo;

            if (!messageInfo.AnyHeaders)
            {
                return;
            }

            MessageHeaders headers = message.Headers;

            KeyValuePair <Type, ArrayList>[] multipleHeaderValues = null;
            ArrayList elementList = null;

            if (messageInfo.UnknownHeaderDescription != null)
            {
                elementList = new ArrayList();
            }

            for (int i = 0; i < headers.Count; i++)
            {
                MessageHeaderInfo        header            = headers[i];
                MessageHeaderDescription headerDescription = messageInfo.HeaderDescriptionTable.Get(header.Name, header.Namespace);
                if (headerDescription != null)
                {
                    if (header.MustUnderstand)
                    {
                        headers.UnderstoodHeaders.Add(header);
                    }

                    object item = null;
                    XmlDictionaryReader headerReader = headers.GetReaderAtHeader(i);
                    try
                    {
                        object dataValue = DeserializeHeaderContents(headerReader, messageDescription, headerDescription);
                        if (headerDescription.TypedHeader)
                        {
                            item = TypedHeaderManager.Create(headerDescription.Type, dataValue, headers[i].MustUnderstand, headers[i].Relay, headers[i].Actor);
                        }
                        else
                        {
                            item = dataValue;
                        }
                    }
                    finally
                    {
                        headerReader.Dispose();
                    }

                    if (headerDescription.Multiple)
                    {
                        if (multipleHeaderValues == null)
                        {
                            multipleHeaderValues = new KeyValuePair <Type, ArrayList> [parameters.Length];
                        }

                        if (multipleHeaderValues[headerDescription.Index].Key == null)
                        {
                            multipleHeaderValues[headerDescription.Index] = new KeyValuePair <System.Type, System.Collections.ArrayList>(headerDescription.TypedHeader ? TypedHeaderManager.GetMessageHeaderType(headerDescription.Type) : headerDescription.Type, new ArrayList());
                        }
                        multipleHeaderValues[headerDescription.Index].Value.Add(item);
                    }
                    else
                    {
                        parameters[headerDescription.Index] = item;
                    }
                }
                else if (messageInfo.UnknownHeaderDescription != null)
                {
                    MessageHeaderDescription unknownHeaderDescription = messageInfo.UnknownHeaderDescription;
                    XmlDictionaryReader      headerReader             = headers.GetReaderAtHeader(i);
                    try
                    {
                        XmlDocument doc       = new XmlDocument();
                        object      dataValue = doc.ReadNode(headerReader);
                        if (dataValue != null && unknownHeaderDescription.TypedHeader)
                        {
                            dataValue = TypedHeaderManager.Create(unknownHeaderDescription.Type, dataValue, headers[i].MustUnderstand, headers[i].Relay, headers[i].Actor);
                        }

                        elementList.Add(dataValue);
                    }
                    finally
                    {
                        headerReader.Dispose();
                    }
                }
            }
            if (multipleHeaderValues != null)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    if (multipleHeaderValues[i].Key != null)
                    {
                        parameters[i] = multipleHeaderValues[i].Value.ToArray(multipleHeaderValues[i].Key);
                    }
                }
            }
            if (messageInfo.UnknownHeaderDescription != null)
            {
                parameters[messageInfo.UnknownHeaderDescription.Index] = elementList.ToArray(messageInfo.UnknownHeaderDescription.TypedHeader ? typeof(MessageHeader <XmlElement>) : typeof(XmlElement));
            }
        }
Beispiel #30
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));
     }
 }
        private object DeserializeHeaderContents(XmlDictionaryReader reader, MessageDescription messageDescription, MessageHeaderDescription headerDescription)
        {
            Type dataContractType = GetSubstituteDataContractType(headerDescription.Type, out bool isQueryable);
            XmlObjectSerializer serializerLocal = _serializerFactory.CreateSerializer(dataContractType, headerDescription.Name, headerDescription.Namespace, _knownTypes);
            object val = serializerLocal.ReadObject(reader);

            if (isQueryable && val != null)
            {
                return(Queryable.AsQueryable((IEnumerable)val));
            }
            return(val);
        }
 bool IEqualityComparerMessageDescription.Equals(MessageDescription x, MessageDescription y)
 {
     if (x.XsdTypeName != y.XsdTypeName)
     {
         return false;
     }
     if (x.Headers.Count != y.Headers.Count)
     {
         return false;
     }
     MessageHeaderDescription[] array = new MessageHeaderDescription[x.Headers.Count];
     x.Headers.CopyTo(array, 0);
     MessageHeaderDescription[] descriptionArray2 = new MessageHeaderDescription[y.Headers.Count];
     y.Headers.CopyTo(descriptionArray2, 0);
     if (x.Headers.Count  1)
     {
         Array.SortMessagePartDescription((MessagePartDescription[]) array, MessagePartDescriptionComparer.Singleton);
         Array.SortMessagePartDescription((MessagePartDescription[]) descriptionArray2, MessagePartDescriptionComparer.Singleton);
     }
     for (int i = 0; i  array.Length; i++)
     {
         if (MessagePartDescriptionComparer.Singleton.Compare(array[i], descriptionArray2[i]) != 0)
         {
             return false;
         }
     }
     return true;
 }