XmlContent Class
- Namespace
- Kampute.HttpClient.Xml
- Assembly
- Kampute.HttpClient.dll
Definition
Represents HTTP content based on XML serialized from an object.
public sealed class XmlContent : HttpContent- Inheritance
- object
- HttpContent
- XmlContent
Remarks
The object is serialized when the content is sent, by the serializer that Serializer selects for its runtime type. Use this class to send XML with PostAsync<T>(this HttpRestClient, string, HttpContent, CancellationToken) and the other helpers that take an HttpContent.
Constructors
XmlContent(object)
Initializes a new instance of the XmlContent class, encoded as UTF-8 without a byte order mark.
public XmlContent(object content)Parameters
contentobject- The object to serialize into XML format.
Exceptions
- ArgumentNullException
- Thrown if
contentisnull.
XmlContent(object, Encoding)
Initializes a new instance of the XmlContent class with the specified character encoding.
public XmlContent(object content, Encoding encoding)Parameters
contentobject- The object to serialize into XML format.
encodingEncoding- The character encoding of the XML.
Exceptions
- ArgumentNullException
- Thrown if
contentorencodingisnull.
Properties
DataContractSettings
Gets or sets the settings of T:System.Runtime.Serialization.DataContractSerializer.
public DataContractSerializerSettings DataContractSettings { get; set; }Property Value
- DataContractSerializerSettings
- The settings used when DataContractSerializer writes the object, or
nullfor its defaults. They have no effect when T:System.Xml.Serialization.XmlSerializer writes the object.
Encoding
Gets the character encoding of the XML.
public Encoding Encoding { get; }Property Value
- Encoding
- The character encoding of the XML.
Serializer
Gets or sets which serializer writes the object.
public XmlSerializerKind Serializer { get; set; }Property Value
- XmlSerializerKind
- The serializer choice. The default is XmlSerializerKind.Auto, which uses DataContractSerializer for types marked with T:System.Runtime.Serialization.DataContractAttribute or T:System.Runtime.Serialization.CollectionDataContractAttribute, and T:System.Xml.Serialization.XmlSerializer for any other type.
Methods
SerializeToStreamAsync(Stream, TransportContext)
Serializes the object to a stream.
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)Parameters
streamStream- The target stream.
contextTransportContext- The transport context.
Returns
- Task
- A completed task, because the object is serialized synchronously.
TryComputeLength(out long)
Indicates that the length of the content is not known in advance.
protected override bool TryComputeLength(out long length)Parameters
lengthlong- Always -1.
Returns
Extension Methods
| AsDeflate(this HttpContent, CompressionLevel) | Wraps the content in content that compresses it with Deflate as it is sent. |
| AsGzip(this HttpContent, CompressionLevel) | Wraps the content in content that compresses it with GZip as it is sent. |
| FindCharacterEncoding(this HttpContent) | Returns the character encoding named by the charset parameter of the Content-Type header. |
| IsReusable(this HttpContent) | Determines whether the content can be sent more than once, as a retry requires. |
