Exemple #1
0
        /// <summary>
        /// Appends the received <see cref="SoapEnvelopeHeaderBlock"/> collection to the existing
        /// ones in the received <see cref="Models.V1Dot2.SoapEnvelope"/>.
        /// </summary>
        /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> to append the headers</param>
        /// <param name="headers">The <see cref="SoapEnvelopeHeaderBlock"/> collection to append</param>
        /// <returns>The <see cref="Models.V1Dot2.SoapEnvelope"/> after changes</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static Models.V1Dot2.SoapEnvelope WithHeaders(
            this Models.V1Dot2.SoapEnvelope envelope, params SoapEnvelopeHeaderBlock[] headers)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }

            if (headers.Length == 0)
            {
                return(envelope);
            }

            var xElementHeaders = new XElement[headers.Length];

            for (var i = 0; i < headers.Length; i++)
            {
                xElementHeaders[i] = SoapClientSettings.Default.SerializationProvider.ToXElement(headers[i]);
            }

            return(envelope.WithHeaders(xElementHeaders));
        }
Exemple #2
0
 /// <summary>
 /// Gets a given <see cref="SoapEnvelopeHeaderBlock"/> by its <see cref="XName"/>.
 /// </summary>
 /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> with the headers.</param>
 /// <param name="name">The <see cref="XName"/> to search.</param>
 /// <returns>The <see cref="SoapEnvelopeHeaderBlock"/> or null if not match is found</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static IEnumerable <T> HeadersWithName <T>(this Models.V1Dot2.SoapEnvelope envelope, XName name)
     where T : SoapEnvelopeHeaderBlock
 {
     return
         (envelope.HeadersWithName(name)
          .Select(e => SoapClientSettings.Default.SerializationProvider.ToObject <T>(e)));
 }
Exemple #3
0
        /// <summary>
        /// Appends the received <see cref="XElement"/> collection to the existing
        /// ones in the received <see cref="Models.V1Dot2.SoapEnvelope"/>.
        /// </summary>
        /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> to append the headers</param>
        /// <param name="headers">The <see cref="SoapEnvelopeHeaderBlock"/> collection to append</param>
        /// <returns>The <see cref="Models.V1Dot2.SoapEnvelope"/> after changes</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static Models.V1Dot2.SoapEnvelope WithHeaders(
            this Models.V1Dot2.SoapEnvelope envelope, params XElement[] headers)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }

            if (headers.Length == 0)
            {
                return(envelope);
            }

            if (envelope.Header == null)
            {
                envelope.Header = new Models.V1Dot2.SoapEnvelopeHeader
                {
                    Headers = headers
                };
            }
            else
            {
                var envelopeHeaders = new List <XElement>(envelope.Header.Headers);
                envelopeHeaders.AddRange(headers);
                envelope.Header.Headers = envelopeHeaders.ToArray();
            }

            return(envelope);
        }
Exemple #4
0
        /// <summary>
        /// Does the <see cref="Models.V1Dot2.SoapEnvelope.Body"/> contains a fault?
        /// </summary>
        /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> to validate</param>
        /// <returns>True if a fault exists</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static bool IsFaulted(this Models.V1Dot2.SoapEnvelope envelope)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }

            return(envelope.Body?.Value != null && envelope.Body.Value.Name == SoapV1Dot2FaultXName);
        }
Exemple #5
0
        /// <summary>
        /// Extracts the <see cref="Models.V1Dot2.SoapEnvelope.Body"/> as a <see cref="Models.V1Dot2.SoapFault"/>.
        /// It will fail to deserialize if the body is not a fault. Consider to
        /// use <see cref="IsFaulted(Models.V1Dot2.SoapEnvelope)"/> first.
        /// </summary>
        /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> to be used</param>
        /// <returns>The <see cref="SoapFault"/></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static Models.V1Dot2.SoapFault Fault(this Models.V1Dot2.SoapEnvelope envelope)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }

            return(envelope.Body == null
                ? null
                : SoapClientSettings.Default.SerializationProvider.ToObject <Models.V1Dot2.SoapFault>(envelope.Body.Value));
        }
Exemple #6
0
        /// <summary>
        /// Gets the first <see cref="XElement"/> header by its <see cref="XName"/>.
        /// </summary>
        /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> with the headers.</param>
        /// <param name="name">The <see cref="XName"/> to search.</param>
        /// <returns>The <see cref="XElement"/> or null if not match is found</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static IEnumerable <XElement> HeadersWithName(this Models.V1Dot2.SoapEnvelope envelope, XName name)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }

            return(envelope.Header == null
                ? Enumerable.Empty <XElement>()
                : envelope.Header.Headers.Where(xElement => xElement.Name == name));
        }
Exemple #7
0
        /// <summary>
        /// Extracts the <see cref="Models.V1Dot2.SoapEnvelope.Body"/> as an object of the given type.
        /// </summary>
        /// <typeparam name="T">The type do be deserialized.</typeparam>
        /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/></param>
        /// <returns>The deserialized object</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="FaultV1Dot1Exception">Thrown if the body contains a fault</exception>
        public static T Body <T>(this Models.V1Dot2.SoapEnvelope envelope)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }

            envelope.ThrowIfFaulted();

            return(SoapClientSettings.Default.SerializationProvider.ToObject <T>(envelope.Body.Value));
        }
Exemple #8
0
        /// <summary>
        /// Gets the first <see cref="XElement"/> header by its <see cref="XName"/>.
        /// </summary>
        /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> with the headers.</param>
        /// <param name="name">The <see cref="XName"/> to search.</param>
        /// <returns>The <see cref="XElement"/> or null if not match is found</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static XElement HeaderWithName(this Models.V1Dot2.SoapEnvelope envelope, XName name)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }

            if (envelope.Header == null || envelope.Header.Headers.Length == 0)
            {
                return(null);
            }

            return(envelope.Header.Headers.FirstOrDefault(xElement => xElement.Name == name));
        }
Exemple #9
0
        /// <summary>
        /// Sets the given <see cref="XElement"/> as the envelope body.
        /// </summary>
        /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> to be used.</param>
        /// <param name="body">The <see cref="XElement"/> to set as the body.</param>
        /// <returns>The <see cref="Models.V1Dot2.SoapEnvelope"/> after changes.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static Models.V1Dot2.SoapEnvelope Body(this Models.V1Dot2.SoapEnvelope envelope, XElement body)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }

            if (envelope.Body == null)
            {
                envelope.Body = new Models.V1Dot2.SoapEnvelopeBody();
            }

            envelope.Body.Value = body;

            return(envelope);
        }
Exemple #10
0
        /// <summary>
        /// Checks if the <see cref="Models.V1Dot2.SoapEnvelope.Body"/> contains a fault
        /// and throws an <see cref="FaultV1Dot2Exception"/> if true.
        /// </summary>
        /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> to validate.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="FaultV1Dot2Exception">Thrown if the body contains a fault</exception>
        public static void ThrowIfFaulted(this Models.V1Dot2.SoapEnvelope envelope)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }

            if (!envelope.IsFaulted())
            {
                return;
            }

            var fault = envelope.Fault();

            throw new FaultV1Dot2Exception
                  {
                      Code   = fault.Code,
                      Reason = fault.Reason,
                      Node   = fault.Node,
                      Role   = fault.Role,
                      Detail = fault.Detail
                  };
        }
Exemple #11
0
 /// <summary>
 /// Appends the received <see cref="SoapEnvelopeHeaderBlock"/> collection to the existing
 /// ones in the received <see cref="Models.V1Dot2.SoapEnvelope"/>.
 /// </summary>
 /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> to append the headers</param>
 /// <param name="headers">The <see cref="SoapEnvelopeHeaderBlock"/> collection to append</param>
 /// <returns>The <see cref="Models.V1Dot2.SoapEnvelope"/> after changes</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static Models.V1Dot2.SoapEnvelope WithHeaders(
     this Models.V1Dot2.SoapEnvelope envelope, IEnumerable <SoapEnvelopeHeaderBlock> headers)
 {
     return(envelope.WithHeaders(headers as SoapEnvelopeHeaderBlock[] ?? headers.ToArray()));
 }
Exemple #12
0
 /// <summary>
 /// Appends the received <see cref="XElement"/> collection to the existing
 /// ones in the received <see cref="Models.V1Dot2.SoapEnvelope"/>.
 /// </summary>
 /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> to append the headers</param>
 /// <param name="headers">The <see cref="SoapEnvelopeHeaderBlock"/> collection to append</param>
 /// <returns>The <see cref="Models.V1Dot2.SoapEnvelope"/> after changes</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static Models.V1Dot2.SoapEnvelope WithHeaders(
     this Models.V1Dot2.SoapEnvelope envelope, IEnumerable <XElement> headers)
 {
     return(envelope.WithHeaders(headers as XElement[] ?? headers.ToArray()));
 }
Exemple #13
0
 /// <summary>
 /// Sets the given entity as the envelope body.
 /// </summary>
 /// <typeparam name="T">The object type</typeparam>
 /// <param name="envelope">The <see cref="Models.V1Dot2.SoapEnvelope"/> to be used.</param>
 /// <param name="body">The entity to set as the body.</param>
 /// <returns>The <see cref="Models.V1Dot2.SoapEnvelope"/> after changes.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static Models.V1Dot2.SoapEnvelope Body <T>(this Models.V1Dot2.SoapEnvelope envelope, T body)
 {
     return(envelope.Body(
                SoapClientSettings.Default.SerializationProvider.ToXElement(body)));
 }