ReadStartElement() публичный Метод

public ReadStartElement ( System localName, System namespaceUri ) : void
localName System
namespaceUri System
Результат void
        public void ReadXml( XmlDictionaryReader reader )
        {
            if ( reader == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "reader" );
            }

            reader.MoveToContent();
            if ( !reader.IsStartElement( XmlEncryptionConstants.Elements.CipherData, XmlEncryptionConstants.Namespace ) )
            {
                throw DiagnosticUtility.ThrowHelperXml( reader, SR.GetString( SR.ID4188 ) );
            }

            reader.ReadStartElement( XmlEncryptionConstants.Elements.CipherData, XmlEncryptionConstants.Namespace );
            reader.ReadStartElement( XmlEncryptionConstants.Elements.CipherValue, XmlEncryptionConstants.Namespace );

            _cipherText = reader.ReadContentAsBase64();
            _iv         = null;

            // <CipherValue>
            reader.MoveToContent();           
            reader.ReadEndElement();

            
            // <CipherData>
            reader.MoveToContent();
            reader.ReadEndElement(); 
        }
 public void ReadFrom(XmlDictionaryReader reader, long maxBufferSize)
 {
     this.ValidateReadState();
     reader.MoveToStartElement(this.OpeningElementName, NamespaceUri);
     this.encoding = reader.GetAttribute(EncodingAttribute, null);
     this.id = reader.GetAttribute(System.ServiceModel.XD.XmlEncryptionDictionary.Id, null) ?? System.ServiceModel.Security.SecurityUniqueId.Create().Value;
     this.wsuId = reader.GetAttribute(System.ServiceModel.XD.XmlEncryptionDictionary.Id, System.ServiceModel.XD.UtilityDictionary.Namespace) ?? System.ServiceModel.Security.SecurityUniqueId.Create().Value;
     this.mimeType = reader.GetAttribute(MimeTypeAttribute, null);
     this.type = reader.GetAttribute(TypeAttribute, null);
     this.ReadAdditionalAttributes(reader);
     reader.Read();
     if (reader.IsStartElement(EncryptionMethodElement.ElementName, NamespaceUri))
     {
         this.encryptionMethod.ReadFrom(reader);
     }
     if (this.tokenSerializer.CanReadKeyIdentifier(reader))
     {
         this.KeyIdentifier = this.tokenSerializer.ReadKeyIdentifier(reader);
     }
     reader.ReadStartElement(CipherDataElementName, NamespaceUri);
     reader.ReadStartElement(CipherValueElementName, NamespaceUri);
     if (maxBufferSize == 0L)
     {
         this.ReadCipherData(reader);
     }
     else
     {
         this.ReadCipherData(reader, maxBufferSize);
     }
     reader.ReadEndElement();
     reader.ReadEndElement();
     this.ReadAdditionalElements(reader);
     reader.ReadEndElement();
     this.State = EncryptionState.Read;
 }
        public static CloseSequenceResponseInfo Create(XmlDictionaryReader reader)
        {
            if (reader == null)
            {
                Fx.Assert("Argument reader cannot be null.");
            }

            CloseSequenceResponseInfo closeSequenceResponseInfo = new CloseSequenceResponseInfo();

            XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(ReliableMessagingVersion.WSReliableMessaging11);

            reader.ReadStartElement(DXD.Wsrm11Dictionary.CloseSequenceResponse, wsrmNs);
            reader.ReadStartElement(XD.WsrmFeb2005Dictionary.Identifier, wsrmNs);
            closeSequenceResponseInfo.Identifier = reader.ReadContentAsUniqueId();
            reader.ReadEndElement();

            while (reader.IsStartElement())
            {
                reader.Skip();
            }

            reader.ReadEndElement();

            return closeSequenceResponseInfo;
        }
        private static object DeserializeStruct(XmlDictionaryReader reader, Type targetType)
        {
            if (targetType.IsDefined(typeof(DataContractAttribute), false))
            {
                Dictionary<string, MemberInfo> dataMembers = GetDataMembers(targetType);
                object targetObject = Activator.CreateInstance(targetType);

                reader.ReadStartElement(XmlRpcProtocol.Struct);
                
                while( reader.NodeType != XmlNodeType.EndElement )
                {
                    string memberName;

                    reader.ReadStartElement(XmlRpcProtocol.Member);
                    reader.ReadStartElement(XmlRpcProtocol.Name);
                    memberName = reader.ReadContentAsString();
                    reader.ReadEndElement();
                    
                    reader.ReadStartElement(XmlRpcProtocol.Value);
                    reader.MoveToContent();
                    if (dataMembers.ContainsKey(memberName))
                    {
                        MemberInfo member = dataMembers[memberName];
                        if (member is PropertyInfo)
                        {
                            ((PropertyInfo)member).SetValue(
                                targetObject, 
                                Deserialize(reader, ((PropertyInfo)member).PropertyType), 
                                BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.NonPublic, 
                                null, null,
                                CultureInfo.CurrentCulture);
                        }
                        else if (member is FieldInfo)
                        {
                            ((FieldInfo)member).SetValue(
                                targetObject,
                                Deserialize(reader, ((FieldInfo)member).FieldType),
                                BindingFlags.Instance|BindingFlags.SetField|BindingFlags.Public|BindingFlags.NonPublic,
                                null,
                                CultureInfo.CurrentCulture);
                        }
                    }
                    reader.ReadEndElement(); // value
                    reader.ReadEndElement(); // member
                }
                reader.ReadEndElement(); // struct
                reader.MoveToContent();
                return targetObject;                
            }
            else
            {
                throw new InvalidOperationException();
            }
            
        }
Пример #5
0
		protected override void OnReadBodyContents(XmlDictionaryReader reader)
		{
			base.OnReadBodyContents(reader);
			reader.ReadStartElement("ResourceCreated", "http://schemas.xmlsoap.org/ws/2004/09/transfer");
			reader.Skip();
			reader.ReadStartElement("ReferenceParameters", "http://www.w3.org/2005/08/addressing");
			XmlUtility.DeserializeObjectReference(reader, out this._objectReference);
			this._instance = reader.ReadElementString("instance", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
			reader.ReadEndElement();
			reader.ReadEndElement();
			DirectoryControlSerializer.Deserialize(reader, out this._controls, false, false);
			reader.ReadEndElement();
		}
 public static CloseSequenceResponseInfo Create(XmlDictionaryReader reader)
 {
     CloseSequenceResponseInfo info = new CloseSequenceResponseInfo();
     XmlDictionaryString namespaceUri = WsrmIndex.GetNamespace(ReliableMessagingVersion.WSReliableMessaging11);
     reader.ReadStartElement(DXD.Wsrm11Dictionary.CloseSequenceResponse, namespaceUri);
     reader.ReadStartElement(XD.WsrmFeb2005Dictionary.Identifier, namespaceUri);
     info.Identifier = reader.ReadContentAsUniqueId();
     reader.ReadEndElement();
     while (reader.IsStartElement())
     {
         reader.Skip();
     }
     reader.ReadEndElement();
     return info;
 }
Пример #7
0
		protected override void OnReadBodyContents(XmlDictionaryReader reader)
		{
			reader.ReadStartElement("BaseObjectSearchResponse", "http://schemas.microsoft.com/2006/11/IdentityManagement/DirectoryAccess");
			ResultSerializer.Deserialize(reader, ResultSerializer.ResultDialect.XPath1, out this._entry);
			DirectoryControlSerializer.Deserialize(reader, out this._controls, false, false);
			reader.ReadEndElement();
		}
Пример #8
0
 public override object ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
 {
     reader.ReadStartElement("Data");
     var data = reader.ReadContentAsBase64();
     reader.ReadEndElement();
     return DecodeObject(data);
 }
        internal X509CertificateEndpointIdentity(XmlDictionaryReader reader)
        {
            if (reader == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");

            reader.MoveToContent();
            if (reader.IsEmptyElement)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.UnexpectedEmptyElementExpectingClaim, XD.AddressingDictionary.X509v3Certificate.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value)));

            reader.ReadStartElement(XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace);
            while (reader.IsStartElement(XD.XmlSignatureDictionary.X509Certificate, XD.XmlSignatureDictionary.Namespace))
            {
                reader.MoveToContent();
                X509Certificate2 certificate = new X509Certificate2(Convert.FromBase64String(reader.ReadContentAsString()));
                if (certificateCollection.Count == 0)
                {
                    // This is the first certificate. We assume this as the primary 
                    // certificate and initialize the base class.
                    Initialize(new Claim(ClaimTypes.Thumbprint, certificate.GetCertHash(), Rights.PossessProperty));
                }

                certificateCollection.Add(certificate);
            }

            reader.ReadEndElement();

            if (certificateCollection.Count == 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.UnexpectedEmptyElementExpectingClaim, XD.AddressingDictionary.X509v3Certificate.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value)));
        }
 public BinaryBodyReader(XmlDictionaryReader reader)
 {
     reader.ReadStartElement(BinaryElementName);
     _data = reader.ReadContentAsBase64();
     if (reader.NodeType == XmlNodeType.Text) reader.Read();
     reader.ReadEndElement();
 }
Пример #11
0
 public static TotalItemsCountEstimate ReadFrom(XmlDictionaryReader reader)
 {
    reader.ReadStartElement(ElementName, ManagementNamespaces.Namespace);
    int value = XmlConvert.ToInt32(reader.ReadString());
    TotalItemsCountEstimate result = new TotalItemsCountEstimate(value);
    reader.ReadEndElement();
    return result;
 }
Пример #12
0
      public static ResourceUriHeader ReadFrom(XmlDictionaryReader reader)
      {
		 reader.ReadStartElement(ElementName, ManagementNamespaces.Namespace);
         string result = reader.Value;
         reader.Read();
         reader.ReadEndElement();
         return new ResourceUriHeader(result);
      }
Пример #13
0
            public override SecurityKeyIdentifierClause ReadKeyIdentifierClauseCore(XmlDictionaryReader reader)
            {
                string encryptionMethod = null;
                string carriedKeyName = null;
                SecurityKeyIdentifier encryptingKeyIdentifier = null;
                byte[] encryptedKey = null;

                reader.ReadStartElement(XD.XmlEncryptionDictionary.EncryptedKey, NamespaceUri);
                
                if (reader.IsStartElement(XD.XmlEncryptionDictionary.EncryptionMethod, NamespaceUri))
                {
                    encryptionMethod = reader.GetAttribute(XD.XmlEncryptionDictionary.AlgorithmAttribute, null);
                    bool isEmptyElement = reader.IsEmptyElement;
                    reader.ReadStartElement();
                    if (!isEmptyElement)
                    {
                        while (reader.IsStartElement())
                        {
                            reader.Skip();
                        }
                        reader.ReadEndElement();
                    }
                }

                if (this.securityTokenSerializer.CanReadKeyIdentifier(reader))
                {
                    encryptingKeyIdentifier = this.securityTokenSerializer.ReadKeyIdentifier(reader);
                }
                
                reader.ReadStartElement(XD.XmlEncryptionDictionary.CipherData, NamespaceUri);
                reader.ReadStartElement(XD.XmlEncryptionDictionary.CipherValue, NamespaceUri);
                encryptedKey = reader.ReadContentAsBase64();
                reader.ReadEndElement();
                reader.ReadEndElement();

                if (reader.IsStartElement(XD.XmlEncryptionDictionary.CarriedKeyName, NamespaceUri))
                {
                    reader.ReadStartElement();
                    carriedKeyName = reader.ReadString();                    
                    reader.ReadEndElement();
                }
                
                reader.ReadEndElement();

                return new EncryptedKeyIdentifierClause(encryptedKey, encryptionMethod, encryptingKeyIdentifier, carriedKeyName);
            }
Пример #14
0
 public static IdentifierHeader ReadFrom(XmlDictionaryReader reader)
 {
    reader.ReadStartElement(ElementName, EventingActions.Namespace);
    string result = reader.Value;
    reader.Read();
    reader.ReadEndElement();
    return new IdentifierHeader(result);
 }
Пример #15
0
 static PollingDuplexSession ReadHeaderValue(XmlDictionaryReader reader)
 {
     string str = null;
     string str2 = null;
     if (reader.IsStartElement("Duplex", "http://schemas.microsoft.com/2008/04/netduplex"))
     {
         reader.ReadStartElement();
         reader.MoveToContent();
         while (reader.IsStartElement())
         {
             if (reader.IsStartElement("SessionId", "http://schemas.microsoft.com/2008/04/netduplex"))
             {
                 if (!string.IsNullOrEmpty(str2))
                 {
                     throw new InvalidOperationException("Multiple sessionId elements in a duplex header.");
                 }
                 str2 = reader.ReadElementContentAsString();
                 if (string.IsNullOrEmpty(str2))
                 {
                     throw new InvalidOperationException("Invalid sessionId element content in a duplex header.");
                 }
             }
             else
             {
                 if (reader.IsStartElement("Address", "http://schemas.microsoft.com/2008/04/netduplex"))
                 {
                     if (!string.IsNullOrEmpty(str))
                     {
                         throw new InvalidOperationException("Multiple address elements in a duplex header.");
                     }
                     str = reader.ReadElementContentAsString();
                     if (string.IsNullOrEmpty(str))
                     {
                         throw new InvalidOperationException("Invalid address element in a duplex header.");
                     }
                     continue;
                 }
                 if (reader.IsStartElement("CloseSession", "http://schemas.microsoft.com/2008/04/netduplex"))
                 {
                     reader.Skip();
                     continue;
                 }
                 reader.Skip();
             }
         }
         reader.ReadEndElement();
     }
     if (str == null)
     {
         throw new InvalidOperationException("Missing address in a duplex header.");
     }
     if (str2 == null)
     {
         throw new InvalidOperationException("Missing sessionId in a duplex header.");
     }
     return new PollingDuplexSession(str, str2);
 }
 public static WsrmAckRequestedInfo ReadHeader(ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader, MessageHeaderInfo header)
 {
     WsrmFeb2005Dictionary dictionary = XD.WsrmFeb2005Dictionary;
     XmlDictionaryString namespaceUri = WsrmIndex.GetNamespace(reliableMessagingVersion);
     reader.ReadStartElement();
     reader.ReadStartElement(dictionary.Identifier, namespaceUri);
     UniqueId sequenceID = reader.ReadContentAsUniqueId();
     reader.ReadEndElement();
     if ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) && reader.IsStartElement(dictionary.MessageNumber, namespaceUri))
     {
         reader.ReadStartElement();
         WsrmUtilities.ReadSequenceNumber(reader, true);
         reader.ReadEndElement();
     }
     while (reader.IsStartElement())
     {
         reader.Skip();
     }
     reader.ReadEndElement();
     return new WsrmAckRequestedInfo(sequenceID, header);
 }
Пример #17
0
        /// <summary>
        /// Reads the body of an object
        /// </summary>
        public override object ReadObject(System.Xml.XmlDictionaryReader reader, bool verifyObjectName)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            reader.MoveToContent();
            bool isSelfClosed = reader.IsEmptyElement, isNil = reader.GetAttribute("nil") == "true";

            reader.ReadStartElement(PROTO_ELEMENT);

            // explicitly null
            if (isNil)
            {
                if (!isSelfClosed)
                {
                    reader.ReadEndElement();
                }
                return(null);
            }
            if (isSelfClosed) // no real content
            {
                if (isList || isEnum)
                {
                    return(model.Deserialize(Stream.Null, null, type, null));
                }
                using (ProtoReader protoReader = new ProtoReader(Stream.Null, model, null))
                {
                    return(model.Deserialize(key, null, protoReader));
                }
            }

            object result;

            Helpers.DebugAssert(reader.CanReadBinaryContent, "CanReadBinaryContent");
            using (MemoryStream ms = new MemoryStream(reader.ReadContentAsBase64()))
            {
                if (isList || isEnum)
                {
                    result = model.Deserialize(ms, null, type, null);
                }
                else
                {
                    using (ProtoReader protoReader = new ProtoReader(ms, model, null))
                    {
                        result = model.Deserialize(key, null, protoReader);
                    }
                }
            }
            reader.ReadEndElement();
            return(result);
        }
 public static CloseSequenceInfo Create(XmlDictionaryReader reader)
 {
     CloseSequenceInfo info = new CloseSequenceInfo();
     XmlDictionaryString namespaceUri = WsrmIndex.GetNamespace(ReliableMessagingVersion.WSReliableMessaging11);
     Wsrm11Dictionary dictionary = DXD.Wsrm11Dictionary;
     reader.ReadStartElement(dictionary.CloseSequence, namespaceUri);
     reader.ReadStartElement(XD.WsrmFeb2005Dictionary.Identifier, namespaceUri);
     info.Identifier = reader.ReadContentAsUniqueId();
     reader.ReadEndElement();
     if (reader.IsStartElement(dictionary.LastMsgNumber, namespaceUri))
     {
         reader.ReadStartElement();
         info.LastMsgNumber = WsrmUtilities.ReadSequenceNumber(reader, false);
         reader.ReadEndElement();
     }
     while (reader.IsStartElement())
     {
         reader.Skip();
     }
     reader.ReadEndElement();
     return info;
 }
 public static CreateSequenceResponseInfo Create(AddressingVersion addressingVersion, ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader)
 {
     CreateSequenceResponseInfo info = new CreateSequenceResponseInfo();
     WsrmFeb2005Dictionary dictionary = XD.WsrmFeb2005Dictionary;
     XmlDictionaryString namespaceUri = WsrmIndex.GetNamespace(reliableMessagingVersion);
     reader.ReadStartElement(dictionary.CreateSequenceResponse, namespaceUri);
     reader.ReadStartElement(dictionary.Identifier, namespaceUri);
     info.Identifier = reader.ReadContentAsUniqueId();
     reader.ReadEndElement();
     if (reader.IsStartElement(dictionary.Expires, namespaceUri))
     {
         reader.ReadElementContentAsTimeSpan();
     }
     if ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) && reader.IsStartElement(DXD.Wsrm11Dictionary.IncompleteSequenceBehavior, namespaceUri))
     {
         string str2 = reader.ReadElementContentAsString();
         if (((str2 != "DiscardEntireSequence") && (str2 != "DiscardFollowingFirstGap")) && (str2 != "NoDiscard"))
         {
             string message = System.ServiceModel.SR.GetString("CSResponseWithInvalidIncompleteSequenceBehavior");
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(message));
         }
     }
     if (reader.IsStartElement(dictionary.Accept, namespaceUri))
     {
         reader.ReadStartElement();
         info.AcceptAcksTo = EndpointAddress.ReadFrom(addressingVersion, reader, dictionary.AcksTo, namespaceUri);
         while (reader.IsStartElement())
         {
             reader.Skip();
         }
         reader.ReadEndElement();
     }
     while (reader.IsStartElement())
     {
         reader.Skip();
     }
     reader.ReadEndElement();
     return info;
 }
 public static MaxEnvelopeSizeHeader ReadFrom(XmlDictionaryReader reader)
 {
     reader.ReadStartElement(ElementName, Const.ManagementNamespace);
     var fragment = new StringBuilder();
     while (reader.NodeType == XmlNodeType.Text)
     {
         fragment.Append(reader.Value);
         reader.Read();
     }
     var result = new MaxEnvelopeSizeHeader(int.Parse(fragment.ToString()));
     reader.ReadEndElement();
     return result;
 }
 internal RsaEndpointIdentity(XmlDictionaryReader reader)
 {
     reader.ReadStartElement(XD.XmlSignatureDictionary.RsaKeyValue, XD.XmlSignatureDictionary.Namespace);
     byte[] modulus = Convert.FromBase64String(reader.ReadElementString(XD.XmlSignatureDictionary.Modulus.Value, XD.XmlSignatureDictionary.Namespace.Value));
     byte[] exponent = Convert.FromBase64String(reader.ReadElementString(XD.XmlSignatureDictionary.Exponent.Value, XD.XmlSignatureDictionary.Namespace.Value));
     reader.ReadEndElement();
     RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
     RSAParameters parameters = new RSAParameters();
     parameters.Exponent = exponent;
     parameters.Modulus = modulus;
     rsa.ImportParameters(parameters);
     base.Initialize(Claim.CreateRsaClaim(rsa));
 }
 public static FragmentTransferHeader ReadFrom(XmlDictionaryReader reader)
 {
     reader.ReadStartElement(ElementName, Const.ManagementNamespace);         
    StringBuilder fragment = new StringBuilder();
    while (reader.NodeType == XmlNodeType.Text)
    {
       fragment.Append(reader.Value);
       reader.Read();
    }
    FragmentTransferHeader result = new FragmentTransferHeader(fragment.ToString());
    reader.ReadEndElement();         
    return result;
 }
        public static MakeConnectionMessageInfo Create(XmlDictionaryReader reader)
        {
            MakeConnectionMessageInfo makeConnectionInfo = new MakeConnectionMessageInfo();

            if (reader.IsStartElement(MakeConnectionConstants.MakeConnectionMessage.Name, MakeConnectionConstants.Namespace))
            {
                reader.ReadStartElement();
                reader.MoveToContent();

                while (reader.IsStartElement())
                {
                    if (reader.IsStartElement(MakeConnectionConstants.MakeConnectionMessage.AddressElement, MakeConnectionConstants.Namespace))
                    {
                        if (!string.IsNullOrEmpty(makeConnectionInfo.Address))
                        {
                            makeConnectionInfo.MultipleAddressHeaders = true;
                            reader.Skip();
                        }
                        else
                        {
                            makeConnectionInfo.Address = reader.ReadElementContentAsString();
                        }
                    }
                    else if (reader.IsStartElement(MakeConnectionConstants.MakeConnectionMessage.IdentifierElement, MakeConnectionConstants.Namespace))
                    {
                        if (makeConnectionInfo.Identifier != null)
                        {
                            makeConnectionInfo.MultipleIdentifierHeaders = true;
                            reader.Skip();
                        }
                        else
                        {
                            makeConnectionInfo.Identifier = reader.ReadElementContentAsUniqueId();
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(makeConnectionInfo.UnknownSelection))
                        {
                            makeConnectionInfo.UnknownSelection = reader.LocalName;
                        }

                        reader.Skip();
                    }
                }

                reader.ReadEndElement();
            }

            return makeConnectionInfo;
        }
 protected override void ReadAdditionalElements(XmlDictionaryReader reader)
 {
     if (reader.IsStartElement(System.ServiceModel.Security.ReferenceList.ElementName, EncryptedType.NamespaceUri))
     {
         this.referenceList = new System.ServiceModel.Security.ReferenceList();
         this.referenceList.ReadFrom(reader);
     }
     if (reader.IsStartElement(CarriedKeyElementName, EncryptedType.NamespaceUri))
     {
         reader.ReadStartElement(CarriedKeyElementName, EncryptedType.NamespaceUri);
         this.carriedKeyName = reader.ReadString();
         reader.ReadEndElement();
     }
 }
        public static TerminateSequenceInfo Create(ReliableMessagingVersion reliableMessagingVersion,
            XmlDictionaryReader reader)
        {
            if (reader == null)
            {
                Fx.Assert("Argument reader cannot be null.");
            }

            TerminateSequenceInfo terminateSequenceInfo = new TerminateSequenceInfo();
            WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
            XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(reliableMessagingVersion);

            reader.ReadStartElement(wsrmFeb2005Dictionary.TerminateSequence, wsrmNs);

            reader.ReadStartElement(wsrmFeb2005Dictionary.Identifier, wsrmNs);
            terminateSequenceInfo.Identifier = reader.ReadContentAsUniqueId();
            reader.ReadEndElement();

            if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
            {
                if (reader.IsStartElement(DXD.Wsrm11Dictionary.LastMsgNumber, wsrmNs))
                {
                    reader.ReadStartElement();
                    terminateSequenceInfo.LastMsgNumber = WsrmUtilities.ReadSequenceNumber(reader, false);
                    reader.ReadEndElement();
                }
            }

            while (reader.IsStartElement())
            {
                reader.Skip();
            }

            reader.ReadEndElement();

            return terminateSequenceInfo;
        }
Пример #26
0
        public virtual void ReadXml( XmlDictionaryReader reader )
        {
            if ( reader == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "reader" );
            }

            reader.MoveToContent();
            if ( reader.IsStartElement( XD.XmlSignatureDictionary.KeyInfo.Value, XD.XmlSignatureDictionary.Namespace.Value ) )
            {
                // <KeyInfo>
                reader.ReadStartElement();

                while ( reader.IsStartElement() )
                {
                    // <RetrievalMethod>
                    if ( reader.IsStartElement( XmlSignatureConstants.Elements.RetrievalMethod, XD.XmlSignatureDictionary.Namespace.Value ) )
                    {
                        string method = reader.GetAttribute( XD.XmlSignatureDictionary.URI.Value );
                        if ( !string.IsNullOrEmpty( method ) )
                        {
                            _retrieval = method;
                        }
                        reader.Skip();
                    }
                    // check if internal serializer can handle clause
                    else if ( _keyInfoSerializer.CanReadKeyIdentifierClause( reader ) )
                    {
                        _ski.Add( _keyInfoSerializer.ReadKeyIdentifierClause( reader ) );
                    }
                    // trace we skipped over an element
                    else if ( reader.IsStartElement() )
                    {
                        string xml = reader.ReadOuterXml();

                        if ( DiagnosticUtility.ShouldTraceWarning )
                        {
                            TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.GetString( SR.ID8023, reader.Name, reader.NamespaceURI, xml ) );
                        }
                    }
                    reader.MoveToContent();
                }

                reader.MoveToContent();
                reader.ReadEndElement();
            }
        }
 public void ReadFrom(XmlDictionaryReader reader)
 {
     reader.ReadStartElement(ElementName, NamespaceUri);
     while (reader.IsStartElement())
     {
         string item = DataReference.ReadFrom(reader);
         if (this.referredIds.Contains(item))
         {
             throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("InvalidDataReferenceInReferenceList", new object[] { "#" + item })));
         }
         this.referredIds.Add(item);
     }
     reader.ReadEndElement();
     if (this.DataReferenceCount == 0)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("ReferenceListCannotBeEmpty")));
     }
 }
Пример #28
0
 public void ReadFrom(XmlDictionaryReader reader)
 {
     reader.ReadStartElement(ElementName, NamespaceUri);
     while (reader.IsStartElement())
     {
         string id = DataReference.ReadFrom(reader);
         if (this.referredIds.Contains(id))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                 new SecurityMessageSerializationException(SR.GetString(SR.InvalidDataReferenceInReferenceList, "#" + id)));
         }
         this.referredIds.Add(id);
     }
     reader.ReadEndElement(); // ReferenceList
     if (this.DataReferenceCount == 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityMessageSerializationException(SR.GetString(SR.ReferenceListCannotBeEmpty)));
     }
 }
 public MessageNumberRolloverFault(FaultCode code, FaultReason reason, XmlDictionaryReader detailReader, ReliableMessagingVersion reliableMessagingVersion) : base(code, "MessageNumberRollover", reason, true, true)
 {
     try
     {
         base.SequenceID = WsrmUtilities.ReadIdentifier(detailReader, reliableMessagingVersion);
         if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
         {
             ulong num;
             detailReader.ReadStartElement(DXD.Wsrm11Dictionary.MaxMessageNumber, WsrmIndex.GetNamespace(reliableMessagingVersion));
             if (!ulong.TryParse(detailReader.ReadContentAsString(), out num) || (num <= 0L))
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidSequenceNumber", new object[] { num })));
             }
             detailReader.ReadEndElement();
         }
     }
     finally
     {
         detailReader.Close();
     }
 }
Пример #30
0
 public virtual void ReadXml(XmlDictionaryReader reader)
 {
     if (reader == null)
     {
         throw DiagnosticUtil.ExceptionUtil.ThrowHelperArgumentNull("reader");
     }
     reader.MoveToContent();
     if (reader.IsStartElement("KeyInfo", "http://www.w3.org/2000/09/xmldsig#"))
     {
         reader.ReadStartElement();
         while (reader.IsStartElement())
         {
             if (reader.IsStartElement("RetrievalMethod", "http://www.w3.org/2000/09/xmldsig#"))
             {
                 string attribute = reader.GetAttribute("URI");
                 if (!string.IsNullOrEmpty(attribute))
                 {
                     this._retrieval = attribute;
                 }
                 reader.Skip();
             }
             else if (this._keyInfoSerializer.CanReadKeyIdentifierClause(reader))
             {
                 this._ski.Add(this._keyInfoSerializer.ReadKeyIdentifierClause(reader));
             }
             else if (reader.IsStartElement())
             {
                 string str2 = reader.ReadOuterXml();
                 //if (DiagnosticUtil.TraceUtil.ShouldTrace(TraceEventType.Warning))
                 //{
                 //    DiagnosticUtil.TraceUtil.TraceString(TraceEventType.Warning, SR.GetString("ID8023", new object[] { reader.Name, reader.NamespaceURI, str2 }), new object[0]);
                 //}
             }
             reader.MoveToContent();
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
 }
Пример #31
0
        private object[] GetRequestArguments(Message requestMessage, System.Xml.XmlDictionaryReader xmlReader, OperationDescription operation, HttpContext httpContext)
        {
            var arguments = new object[operation.AllParameters.Length];

            IEnumerable <Type> serviceKnownTypes = operation
                                                   .GetServiceKnownTypesHierarchy()
                                                   .Select(x => x.Type);

            // if any ordering issues, possible to rewrite like:

            /*while (!xmlReader.EOF)
             * {
             *      var parameterInfo = operation.InParameters.FirstOrDefault(p => p.Name == xmlReader.LocalName && p.Namespace == xmlReader.NamespaceURI);
             *      if (parameterInfo == null)
             *      {
             *              xmlReader.Skip();
             *              continue;
             *      }
             *      var parameterName = parameterInfo.Name;
             *      var parameterNs = parameterInfo.Namespace;
             *      ...
             * }*/

            // Find the element for the operation's data
            if (!operation.IsMessageContractRequest)
            {
                xmlReader.ReadStartElement(operation.Name, operation.Contract.Namespace);

                foreach (var parameterInfo in operation.InParameters)
                {
                    var parameterType = parameterInfo.Parameter.ParameterType;

                    if (parameterType == typeof(HttpContext))
                    {
                        arguments[parameterInfo.Index] = httpContext;
                    }
                    else
                    {
                        var argumentValue = _serializerHelper.DeserializeInputParameter(
                            xmlReader,
                            parameterType,
                            parameterInfo.Name,
                            operation.Contract.Namespace,
                            parameterInfo.Parameter.Member,
                            serviceKnownTypes);

                        //fix https://github.com/DigDes/SoapCore/issues/379 (hack, need research)
                        if (argumentValue == null)
                        {
                            argumentValue = _serializerHelper.DeserializeInputParameter(
                                xmlReader,
                                parameterType,
                                parameterInfo.Name,
                                parameterInfo.Namespace,
                                parameterInfo.Parameter.Member,
                                serviceKnownTypes);
                        }

                        arguments[parameterInfo.Index] = argumentValue;
                    }
                }
            }
            else
            {
                // MessageContracts are constrained to having one "InParameter". We can do special logic on
                // for this
                Debug.Assert(operation.InParameters.Length == 1, "MessageContracts are constrained to having one 'InParameter'");

                var parameterInfo = operation.InParameters[0];
                var parameterType = parameterInfo.Parameter.ParameterType;

                var messageContractAttribute = parameterType.GetCustomAttribute <MessageContractAttribute>();

                Debug.Assert(messageContractAttribute != null, "operation.IsMessageContractRequest should be false if this is null");

                var @namespace = parameterInfo.Namespace ?? operation.Contract.Namespace;

                if (messageContractAttribute.IsWrapped && !parameterType.GetMembersWithAttribute <MessageHeaderAttribute>().Any())
                {
                    //https://github.com/DigDes/SoapCore/issues/385
                    if (operation.DispatchMethod.GetCustomAttribute <XmlSerializerFormatAttribute>()?.Style == OperationFormatStyle.Rpc)
                    {
                        var importer = new SoapReflectionImporter(@namespace);
                        var map      = new XmlReflectionMember
                        {
                            IsReturnValue = false,
                            MemberName    = parameterInfo.Name,
                            MemberType    = parameterType
                        };
                        var mapping    = importer.ImportMembersMapping(parameterInfo.Name, @namespace, new[] { map }, false, true);
                        var serializer = XmlSerializer.FromMappings(new[] { mapping })[0];
                        var value      = serializer.Deserialize(xmlReader);
                        if (value is object[] o && o.Length > 0)
                        {
                            arguments[parameterInfo.Index] = o[0];
                        }
                    }
                    else
                    {
                        // It's wrapped so we treat it like normal!
                        arguments[parameterInfo.Index] = _serializerHelper.DeserializeInputParameter(
                            xmlReader,
                            parameterInfo.Parameter.ParameterType,
                            parameterInfo.Name,
                            @namespace,
                            parameterInfo.Parameter.Member,
                            serviceKnownTypes);
                    }
                }
                else
                {
                    var messageHeadersMembers = parameterType.GetPropertyOrFieldMembers()
                                                .Where(x => x.GetCustomAttribute <MessageHeaderAttribute>() != null)
                                                .Select(mi => new
                    {
                        MemberInfo = mi,
                        MessageHeaderMemberAttribute = mi.GetCustomAttribute <MessageHeaderAttribute>()
                    }).ToArray();

                    var wrapperObject = Activator.CreateInstance(parameterInfo.Parameter.ParameterType);

                    for (var i = 0; i < requestMessage.Headers.Count; i++)
                    {
                        var header = requestMessage.Headers[i];
                        var member = messageHeadersMembers.FirstOrDefault(x => x.MessageHeaderMemberAttribute.Name == header.Name || x.MemberInfo.Name == header.Name);

                        if (member != null)
                        {
                            var reader = requestMessage.Headers.GetReaderAtHeader(i);

                            var value = _serializerHelper.DeserializeInputParameter(
                                reader, member.MemberInfo.GetPropertyOrFieldType(),
                                member.MessageHeaderMemberAttribute.Name ?? member.MemberInfo.Name,
                                member.MessageHeaderMemberAttribute.Namespace ?? @namespace,
                                member.MemberInfo,
                                serviceKnownTypes);

                            member.MemberInfo.SetValueToPropertyOrField(wrapperObject, value);
                        }
                    }

                    // This object isn't a wrapper element, so we will hunt for the nested message body
                    // member inside of it
                    var messageBodyMembers = parameterType.GetPropertyOrFieldMembers().Where(x => x.GetCustomAttribute <MessageBodyMemberAttribute>() != null).Select(mi => new
                    {
                        Member = mi,
                        MessageBodyMemberAttribute = mi.GetCustomAttribute <MessageBodyMemberAttribute>()
                    }).OrderBy(x => x.MessageBodyMemberAttribute.Order);

                    if (messageContractAttribute.IsWrapped)
                    {
                        xmlReader.Read();
                    }

                    foreach (var messageBodyMember in messageBodyMembers)
                    {
                        var messageBodyMemberAttribute = messageBodyMember.MessageBodyMemberAttribute;
                        var messageBodyMemberInfo      = messageBodyMember.Member;

                        var innerParameterName = messageBodyMemberAttribute.Name ?? messageBodyMemberInfo.Name;
                        var innerParameterNs   = messageBodyMemberAttribute.Namespace ?? @namespace;
                        var innerParameterType = messageBodyMemberInfo.GetPropertyOrFieldType();

                        //xmlReader.MoveToStartElement(innerParameterName, innerParameterNs);
                        var innerParameter = _serializerHelper.DeserializeInputParameter(
                            xmlReader,
                            innerParameterType,
                            innerParameterName,
                            innerParameterNs,
                            parameterInfo.Parameter.Member,
                            serviceKnownTypes);

                        messageBodyMemberInfo.SetValueToPropertyOrField(wrapperObject, innerParameter);
                    }

                    arguments[parameterInfo.Index] = wrapperObject;
                }
            }

            foreach (var parameterInfo in operation.OutParameters)
            {
                if (arguments[parameterInfo.Index] != null)
                {
                    // do not overwrite input ref parameters
                    continue;
                }

                if (parameterInfo.Parameter.ParameterType.Name == "Guid&")
                {
                    arguments[parameterInfo.Index] = Guid.Empty;
                }
                else if (parameterInfo.Parameter.ParameterType.Name == "String&" || parameterInfo.Parameter.ParameterType.GetElementType().IsArray)
                {
                    arguments[parameterInfo.Index] = null;
                }
                else
                {
                    var type = parameterInfo.Parameter.ParameterType.GetElementType();
                    arguments[parameterInfo.Index] = Activator.CreateInstance(type);
                }
            }

            return(arguments);
        }
Пример #32
0
 public override void ReadStartElement(string localName)
 {
     reader.ReadStartElement(localName);
 }
 internal X509CertificateEndpointIdentity(XmlDictionaryReader reader)
 {
     this.certificateCollection = new X509Certificate2Collection();
     if (reader == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
     }
     reader.MoveToContent();
     if (reader.IsEmptyElement)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedEmptyElementExpectingClaim", new object[] { XD.AddressingDictionary.X509v3Certificate.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value })));
     }
     reader.ReadStartElement(XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace);
     while (reader.IsStartElement(XD.XmlSignatureDictionary.X509Certificate, XD.XmlSignatureDictionary.Namespace))
     {
         X509Certificate2 certificate = new X509Certificate2(Convert.FromBase64String(reader.ReadElementString()));
         if (this.certificateCollection.Count == 0)
         {
             base.Initialize(new Claim(ClaimTypes.Thumbprint, certificate.GetCertHash(), Rights.PossessProperty));
         }
         this.certificateCollection.Add(certificate);
     }
     reader.ReadEndElement();
     if (this.certificateCollection.Count == 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedEmptyElementExpectingClaim", new object[] { XD.AddressingDictionary.X509v3Certificate.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value })));
     }
 }