/// <summary> /// Read the policy as a LINQ expression /// </summary> /// <param name="rdr">XmlDictionaryReader for the policy Xml</param> /// <returns></returns> public Expression<Func<ClaimsPrincipal, bool>> ReadPolicy(XmlDictionaryReader rdr) { if (rdr.Name != "policy") { throw new InvalidOperationException("Invalid policy document"); } rdr.Read(); if (!rdr.IsStartElement()) { rdr.ReadEndElement(); // There are no claims inside this policy which means allow access to the page. return AllowAccessForDefaultPagePolicy; } // // Instantiate a parameter for the ClaimsPrincipal so it can be evaluated against // each claim constraint. // ParameterExpression subject = Expression.Parameter(typeof(ClaimsPrincipal), "subject"); Expression<Func<ClaimsPrincipal, bool>> result = ReadNode(rdr, subject); rdr.ReadEndElement(); return result; }
public BinaryBodyReader(XmlDictionaryReader reader) { reader.ReadStartElement(BinaryElementName); _data = reader.ReadContentAsBase64(); if (reader.NodeType == XmlNodeType.Text) reader.Read(); reader.ReadEndElement(); }
public XmlRpcMessage(XmlDictionaryReader paramsSection) : this() { bodyReader = paramsSection; bodyReader.MoveToContent(); isFault = false; }
public override void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver) { if (reader == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader")); if (samlSerializer == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); #pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null. SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary; if (!reader.IsStartElement(dictionary.DoNotCacheCondition, dictionary.Namespace)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.DoNotCacheCondition.Value))); // saml:DoNotCacheCondition is a empty element. So just issue a read for // the empty element. if (reader.IsEmptyElement) { reader.MoveToContent(); reader.Read(); return; } reader.MoveToContent(); reader.Read(); reader.ReadEndElement(); }
public XmlRpcMessage(MessageFault fault) : this() { isFault = true; bodyReader = XmlRpcDataContractSerializationHelper.CreateFaultReader(fault); bodyReader.MoveToContent(); }
private static WsrmHeaderFault CreateWsrmHeaderFault(ReliableMessagingVersion reliableMessagingVersion, FaultCode code, string subcode, FaultReason reason, XmlDictionaryReader detailReader) { if (code.IsSenderFault) { if (subcode == "InvalidAcknowledgement") { return new InvalidAcknowledgementFault(code, reason, detailReader, reliableMessagingVersion); } if (subcode == "MessageNumberRollover") { return new MessageNumberRolloverFault(code, reason, detailReader, reliableMessagingVersion); } if (subcode == "UnknownSequence") { return new UnknownSequenceFault(code, reason, detailReader, reliableMessagingVersion); } if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) { if (subcode == "LastMessageNumberExceeded") { return new LastMessageNumberExceededFault(code, reason, detailReader, reliableMessagingVersion); } } else if ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) && (subcode == "SequenceClosed")) { return new SequenceClosedFault(code, reason, detailReader, reliableMessagingVersion); } } if (!code.IsSenderFault && !code.IsReceiverFault) { return null; } return new SequenceTerminatedFault(code, reason, detailReader, reliableMessagingVersion); }
public virtual void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver) { if (reader == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader")); if (samlSerializer == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); #pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null. SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary; if (reader.IsStartElement(dictionary.Action, dictionary.Namespace)) { // The Namespace attribute is optional. this.ns = reader.GetAttribute(dictionary.ActionNamespaceAttribute, null); reader.MoveToContent(); this.action = reader.ReadString(); if (string.IsNullOrEmpty(this.action)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLActionNameRequiredOnRead))); reader.MoveToContent(); reader.ReadEndElement(); } }
public void ReadXml( XmlDictionaryReader reader ) { if ( reader == null ) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "reader" ); } reader.MoveToContent(); if ( !reader.IsStartElement( XmlEncryptionConstants.Elements.EncryptionMethod, XmlEncryptionConstants.Namespace ) ) { return; } _algorithm = reader.GetAttribute( XmlEncryptionConstants.Attributes.Algorithm, null ); if ( !reader.IsEmptyElement ) { // // Trace unread missing element // string xml = reader.ReadOuterXml(); if ( DiagnosticUtility.ShouldTraceWarning ) { TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.GetString( SR.ID8024, reader.Name, reader.NamespaceURI, xml ) ); } } else { // // Read to the next element // reader.Read(); } }
private Message CreateMessageCopy(Message message, XmlDictionaryReader body) { Message copy = Message.CreateMessage(message.Version,message.Headers.Action,body); copy.Headers.CopyHeaderFrom(message,0); copy.Properties.CopyProperties(message.Properties); return copy; }
public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader, ref int maxSizeOfHeaders) { if (reader.AttributeCount == 0) return emptyArray; XmlAttributeHolder[] attributes = new XmlAttributeHolder[reader.AttributeCount]; reader.MoveToFirstAttribute(); for (int i = 0; i < attributes.Length; i++) { string ns = reader.NamespaceURI; string localName = reader.LocalName; string prefix = reader.Prefix; string value = string.Empty; while (reader.ReadAttributeValue()) { if (value.Length == 0) value = reader.Value; else value += reader.Value; } Deduct(prefix, ref maxSizeOfHeaders); Deduct(localName, ref maxSizeOfHeaders); Deduct(ns, ref maxSizeOfHeaders); Deduct(value, ref maxSizeOfHeaders); attributes[i] = new XmlAttributeHolder(prefix, localName, ns, value); reader.MoveToNextAttribute(); } reader.MoveToElement(); return attributes; }
public UriRewriterBodyWriter(string sourcePattern, string targetPattern, XmlDictionaryReader reader) : base(false) { this.sourcePattern = sourcePattern; this.targetPattern = targetPattern; this.reader = reader; }
protected override DecryptedHeader DecryptHeader(XmlDictionaryReader reader, WrappedKeySecurityToken wrappedKeyToken) { SecurityToken token; EncryptedHeaderXml xml = new EncryptedHeaderXml(base.Version) { SecurityTokenSerializer = base.StandardsManager.SecurityTokenSerializer }; xml.ReadFrom(reader, base.MaxReceivedMessageSize); if (xml.MustUnderstand != this.MustUnderstand) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("EncryptedHeaderAttributeMismatch", new object[] { XD.MessageDictionary.MustUnderstand.Value, xml.MustUnderstand, this.MustUnderstand }))); } if (xml.Relay != this.Relay) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("EncryptedHeaderAttributeMismatch", new object[] { XD.Message12Dictionary.Relay.Value, xml.Relay, this.Relay }))); } if (xml.Actor != this.Actor) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("EncryptedHeaderAttributeMismatch", new object[] { base.Version.Envelope.DictionaryActor, xml.Actor, this.Actor }))); } if (wrappedKeyToken == null) { token = WSSecurityOneDotZeroReceiveSecurityHeader.ResolveKeyIdentifier(xml.KeyIdentifier, base.CombinedPrimaryTokenResolver, false); } else { token = wrappedKeyToken; } base.RecordEncryptionToken(token); using (SymmetricAlgorithm algorithm = WSSecurityOneDotZeroReceiveSecurityHeader.CreateDecryptionAlgorithm(token, xml.EncryptionMethod, base.AlgorithmSuite)) { xml.SetUpDecryption(algorithm); return new DecryptedHeader(xml.GetDecryptedBuffer(), base.SecurityVerifiedMessage.GetEnvelopeAttributes(), base.SecurityVerifiedMessage.GetHeaderAttributes(), base.Version, base.StandardsManager.IdManager, base.ReaderQuotas); } }
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 XmlFilteringReader(string xmlNamespaceUri, string name, XmlDictionaryReader innerReader) { this.xmlNamespaceUri = xmlNamespaceUri; this.name = name; InitializeInnerReader(innerReader); }
public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader, ref int maxSizeOfHeaders) { if (reader.AttributeCount == 0) { return emptyArray; } XmlAttributeHolder[] holderArray = new XmlAttributeHolder[reader.AttributeCount]; reader.MoveToFirstAttribute(); for (int i = 0; i < holderArray.Length; i++) { string namespaceURI = reader.NamespaceURI; string localName = reader.LocalName; string prefix = reader.Prefix; string s = string.Empty; while (reader.ReadAttributeValue()) { if (s.Length == 0) { s = reader.Value; } else { s = s + reader.Value; } } Deduct(prefix, ref maxSizeOfHeaders); Deduct(localName, ref maxSizeOfHeaders); Deduct(namespaceURI, ref maxSizeOfHeaders); Deduct(s, ref maxSizeOfHeaders); holderArray[i] = new XmlAttributeHolder(prefix, localName, namespaceURI, s); reader.MoveToNextAttribute(); } reader.MoveToElement(); return holderArray; }
private Expression<Func<ClaimsPrincipal, bool>> ReadNode(XmlDictionaryReader rdr, ParameterExpression subject) { Expression<Func<ClaimsPrincipal, bool>> policyExpression; if (!rdr.IsStartElement()) { throw new InvalidOperationException("Invalid Policy format."); } switch (rdr.Name) { case "and": policyExpression = ReadAnd(rdr, subject); break; case "or": policyExpression = ReadOr(rdr, subject); break; case "claim": policyExpression = ReadClaim(rdr); break; default: policyExpression = DefaultPolicy; break; } return policyExpression; }
public XmlDelegatedReader(XmlDictionaryReader reader) { if (reader == null) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader")); this.reader = reader; }
public SecurityVerifiedMessage(Message messageToProcess, ReceiveSecurityHeader securityHeader) : base(messageToProcess) { this.securityHeader = securityHeader; if (securityHeader.RequireMessageProtection) { XmlDictionaryReader messageReader; BufferedMessage bufferedMessage = this.InnerMessage as BufferedMessage; if (bufferedMessage != null && this.Headers.ContainsOnlyBufferedMessageHeaders) { messageReader = bufferedMessage.GetMessageReader(); } else { this.messageBuffer = new XmlBuffer(int.MaxValue); XmlDictionaryWriter writer = this.messageBuffer.OpenSection(this.securityHeader.ReaderQuotas); this.InnerMessage.WriteMessage(writer); this.messageBuffer.CloseSection(); this.messageBuffer.Close(); messageReader = this.messageBuffer.GetReader(0); } MoveToSecurityHeader(messageReader, securityHeader.HeaderIndex, true); this.cachedReaderAtSecurityHeader = messageReader; this.state = BodyState.Buffered; } else { this.envelopeAttributes = XmlAttributeHolder.emptyArray; this.headerAttributes = XmlAttributeHolder.emptyArray; this.bodyAttributes = XmlAttributeHolder.emptyArray; this.canDelegateCreateBufferedCopyToInnerMessage = true; } }
/// <summary> /// Reads the XML stream or document with an <see cref="T:System.Xml.XmlDictionaryReader" /> and returns the deserialized object; it also enables you to specify whether the serializer can read the data before attempting to read it. /// </summary> /// <param name="reader">An <see cref="T:System.Xml.XmlDictionaryReader" /> used to read the XML document.</param> /// <param name="verifyObjectName">true to check whether the enclosing XML element name and namespace correspond to the root name and root namespace; otherwise, false to skip the verification.</param> /// <returns> /// The deserialized object. /// </returns> public override object ReadObject(XmlDictionaryReader reader, bool verifyObjectName) { Argument.IsNotNull("reader", reader); var memoryStream = new MemoryStream(reader.ReadElementContentAsBase64()); return BinarySerializerHelper.DiscoverAndDeSerialize(memoryStream, _type); }
void AssertNode (int depth, string localName, XmlNodeType nodeType, string value, string type, XmlDictionaryReader reader, string label) { Assert.AreEqual (localName, reader.LocalName, label + ".LocalName"); Assert.AreEqual (nodeType, reader.NodeType, label + ".NodeType"); Assert.AreEqual (value, reader.Value, label + ".Value"); Assert.AreEqual (type, reader.GetAttribute ("type"), label + ".GetAttribute('type')"); }
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; }
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 XmlRpcMessage(string methodName) : this() { bodyReader = null; isFault = false; properties.Add("XmlRpcMethodName", methodName); }
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 override void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; if (!reader.IsStartElement(samlDictionary.DoNotCacheCondition, samlDictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLBadSchema", new object[] { samlDictionary.DoNotCacheCondition.Value }))); } if (reader.IsEmptyElement) { reader.MoveToContent(); reader.Read(); } else { reader.MoveToContent(); reader.Read(); reader.ReadEndElement(); } }
public override object ReadObject(XmlDictionaryReader reader, bool verifyObjectName) { reader.ReadStartElement("Data"); var data = reader.ReadContentAsBase64(); reader.ReadEndElement(); return DecodeObject(data); }
private void ReadFrom(XmlDictionaryReader reader) { try { reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.Register, this.coordinationXmlDictionaryStrings.Namespace); reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.Protocol, this.coordinationXmlDictionaryStrings.Namespace); this.Protocol = WSAtomicTransactionStrings.WellKnownNameToProtocol(reader.ReadElementContentAsString().Trim(), this.protocolVersion); if (this.Protocol == ControlProtocol.None) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"))); } this.ParticipantProtocolService = EndpointAddress.ReadFrom(MessagingVersionHelper.AddressingVersion(this.protocolVersion), reader, this.coordinationXmlDictionaryStrings.ParticipantProtocolService, this.coordinationXmlDictionaryStrings.Namespace); if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.Loopback, XD.DotNetAtomicTransactionExternalDictionary.Namespace)) { this.Loopback = reader.ReadElementContentAsGuid(); } while (reader.IsStartElement()) { reader.Skip(); } reader.ReadEndElement(); } catch (XmlException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception)); } }
public virtual SamlStatement LoadStatement(XmlDictionaryReader reader, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } if (reader.IsStartElement(this.DictionaryManager.SamlDictionary.AuthenticationStatement, this.DictionaryManager.SamlDictionary.Namespace)) { SamlAuthenticationStatement statement = new SamlAuthenticationStatement(); statement.ReadXml(reader, this, keyInfoSerializer, outOfBandTokenResolver); return statement; } if (reader.IsStartElement(this.DictionaryManager.SamlDictionary.AttributeStatement, this.DictionaryManager.SamlDictionary.Namespace)) { SamlAttributeStatement statement2 = new SamlAttributeStatement(); statement2.ReadXml(reader, this, keyInfoSerializer, outOfBandTokenResolver); return statement2; } if (!reader.IsStartElement(this.DictionaryManager.SamlDictionary.AuthorizationDecisionStatement, this.DictionaryManager.SamlDictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.IdentityModel.SR.GetString("SAMLUnableToLoadUnknownElement", new object[] { reader.LocalName }))); } SamlAuthorizationDecisionStatement statement3 = new SamlAuthorizationDecisionStatement(); statement3.ReadXml(reader, this, keyInfoSerializer, outOfBandTokenResolver); return statement3; }
/// <summary> /// Deserializes an object from <paramref name="reader"/>. /// </summary> /// <param name="reader">The XmlReader to deserialize the object from.</param> /// <param name="verifyObjectName">True if the object's name should be verified prior to deserializing.</param> /// <returns>The deserialized object or null if deserialization failed.</returns> public override object ReadObject(System.Xml.XmlDictionaryReader reader, bool verifyObjectName) { var result = Formatter.Parse(new XmlStateReader(reader as XmlReader)); this.Details = result.Details; this.ResultCode = result.Code; return(result.Structure); }
/// <summary> /// Indicates whether this is the start of an object we are prepared to handle /// </summary> public override bool IsStartObject(System.Xml.XmlDictionaryReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } reader.MoveToContent(); return(reader.NodeType == System.Xml.XmlNodeType.Element && reader.Name == PROTO_ELEMENT); }
public override bool IsStartObject(System.Xml.XmlDictionaryReader reader) { if (this._isStartObject != null) { return(this._isStartObject(reader)); } else { throw new NotImplementedException(); } }
public override object ReadObject(System.Xml.XmlDictionaryReader reader, bool verifyObjectName) { if (this._readContent != null) { return(this._readContent(reader)); } else { throw new NotImplementedException(); } }
/// <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 object Call(string op, string action, string[] varnames, object[] varvals, Type returntype) { requestChannel.Open(TimeSpan.MaxValue); //Message msg = //Message.CreateMessage(MessageVersion.<FromBinding>, // action, // new CustomBodyWriter(op, varnames, varvals, //"<ns passed in from Proxy>")); Message msg = Message.CreateMessage(this.messageVersion, action, new CustomBodyWriter(op, varnames, varvals, "<ns passed in from Proxy>")); Message reply = requestChannel.Request(msg, TimeSpan.MaxValue); System.Xml.XmlDictionaryReader reader = reply.GetReaderAtBodyContents(); reader.ReadToFollowing(op + "Result"); return(reader.ReadElementContentAs(returntype, null)); }
static public void ThrowConversionOverflow(XmlDictionaryReader reader, string value, string type) { ThrowXmlException(reader, SR.XmlConversionOverflow, value, type); }
static public void ThrowXmlDictionaryStringIDOutOfRange(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlDictionaryStringIDRange, XmlDictionaryString.MinKey.ToString(NumberFormatInfo.CurrentInfo), XmlDictionaryString.MaxKey.ToString(NumberFormatInfo.CurrentInfo)); }
static public void ThrowTokenExpected(XmlDictionaryReader reader, string expected, string found) { ThrowXmlException(reader, SR.XmlTokenExpected, expected, found); }
static public void ThrowInvalidBinaryFormat(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlInvalidFormat); }
static public void ThrowMultipleRootElements(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlMultipleRootElements); }
public virtual void WriteNode(XmlDictionaryReader reader, bool defattr) { if (reader == null) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader")); } int d = (reader.NodeType == XmlNodeType.None ? -1 : reader.Depth); do { XmlNodeType nodeType = reader.NodeType; Type type; if (nodeType == XmlNodeType.Text || nodeType == XmlNodeType.Whitespace || nodeType == XmlNodeType.SignificantWhitespace) { // This will advance if necessary, so we don't need to call Read() explicitly WriteTextNode(reader, false); } else if (reader.Depth > d && reader.IsStartArray(out type)) { WriteArrayNode(reader, type); } else { // These will not advance, so we must call Read() explicitly switch (nodeType) { case XmlNodeType.Element: WriteElementNode(reader, defattr); break; case XmlNodeType.CDATA: WriteCData(reader.Value); break; case XmlNodeType.EntityReference: WriteEntityRef(reader.Name); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: WriteProcessingInstruction(reader.Name, reader.Value); break; case XmlNodeType.DocumentType: WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value); break; case XmlNodeType.Comment: WriteComment(reader.Value); break; case XmlNodeType.EndElement: WriteFullEndElement(); break; } if (!reader.Read()) { break; } } }while (d < reader.Depth || (d == reader.Depth && reader.NodeType == XmlNodeType.EndElement)); }
public void WriteArray(XmlDictionaryWriter writer, string prefix, TArgument localName, TArgument namespaceUri, XmlDictionaryReader reader) { int count; if (reader.TryGetArrayLength(out count)) { count = Math.Min(count, 256); } else { count = 256; } TArray[] array = new TArray[count]; while (true) { int actual = ReadArray(reader, localName, namespaceUri, array, 0, array.Length); if (actual == 0) { break; } WriteArray(writer, prefix, localName, namespaceUri, array, 0, actual); } }
protected abstract int ReadArray(XmlDictionaryReader reader, TArgument localName, TArgument namespaceUri, TArray[] array, int offset, int count);
protected override int ReadArray(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString namespaceUri, Guid[] array, int offset, int count) { return(reader.ReadArray(localName, namespaceUri, array, offset, count)); }
/// <summary> /// Returns true if the current node of <paramref name="reader"/> is suitable to start deserialization. /// </summary> public override bool IsStartObject(System.Xml.XmlDictionaryReader reader) { return(reader.NamespaceURI == "urn:hl7-org:v3"); }
/// <summary> /// Indicates whether this is the start of an object we are prepared to handle /// </summary> public override bool IsStartObject(System.Xml.XmlDictionaryReader reader) { reader.MoveToContent(); return(reader.NodeType == System.Xml.XmlNodeType.Element && reader.Name == PROTO_ELEMENT); }
static public void ThrowDeclarationNotFirst(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlDeclNotFirst); }
static public void ThrowStartElementExpected(XmlDictionaryReader reader, string name) { ThrowXmlException(reader, SR.XmlStartElementNameExpected, name, GetWhatWasFound(reader)); }
static public void ThrowInvalidRootData(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlInvalidRootData); }
static public void ThrowEmptyNamespace(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlEmptyNamespaceRequiresNullPrefix); }
static public void ThrowXmlDictionaryStringIDUndefinedSession(XmlDictionaryReader reader, int key) { ThrowXmlException(reader, SR.XmlDictionaryStringIDUndefinedSession, key.ToString(NumberFormatInfo.CurrentInfo)); }
static public void ThrowDuplicateAttribute(XmlDictionaryReader reader, string prefix1, string prefix2, string localName, string ns) { ThrowXmlException(reader, SR.XmlDuplicateAttribute, GetName(prefix1, localName), GetName(prefix2, localName), ns); }
static public void ThrowTagMismatch(XmlDictionaryReader reader, string expectedPrefix, string expectedLocalName, string foundPrefix, string foundLocalName) { ThrowXmlException(reader, SR.XmlTagMismatch, GetName(expectedPrefix, expectedLocalName), GetName(foundPrefix, foundLocalName)); }
static public void ThrowUnexpectedEndOfFile(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlUnexpectedEndOfFile, ((XmlBaseReader)reader).GetOpenElements()); }
static public void ThrowInvalidCharRef(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlInvalidCharRef); }
private static void ThrowXmlException(XmlDictionaryReader reader, string res, string arg1, string arg2) { ThrowXmlException(reader, res, arg1, arg2, null); }
static public void ThrowInvalidXml(XmlDictionaryReader reader, byte b) { ThrowXmlException(reader, SR.XmlInvalidXmlByte, b.ToString("X2", CultureInfo.InvariantCulture)); }
static public void ThrowUnexpectedEndElement(XmlDictionaryReader reader) { ThrowXmlException(reader, SR.XmlUnexpectedEndElement); }
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); }
public override void ReadXml (XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoTokenSerializer, SecurityTokenResolver outOfBandTokenResolver) { throw new NotImplementedException (); }
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 }))); } }