Table of Contents

Class HttpRestClientXmlExtensions

Namespace
Kampute.HttpClient.Xml
Assembly
Kampute.HttpClient.Xml.dll

Provides extension methods for HttpRestClient to support XML-based HTTP operations.

public static class HttpRestClientXmlExtensions
Inheritance
HttpRestClientXmlExtensions
Inherited Members

Remarks

This static class extends HttpRestClient with methods tailored for handling HTTP requests and responses involving XML data. It facilitates the sending and receiving of XML content by abstracting the complexities of serialization and deserialization of XML to and from .NET objects.

Methods

AcceptXml(HttpRestClient)

Configures the HttpRestClient to accept XML responses by adding a XmlContentDeserializer in its response deserializers collection.

public static XmlContentDeserializer AcceptXml(this HttpRestClient client)

Parameters

client HttpRestClient

The HttpRestClient instance to configure.

Returns

XmlContentDeserializer

The XmlContentDeserializer used for XML content deserialization.

Remarks

If the client already has a XmlContentDeserializer, this method does nothing. Otherwise, it adds a new XmlContentDeserializer to the client's response deserializers.

PatchAsXmlAsync(HttpRestClient, string, object, CancellationToken)

Sends an asynchronous PATCH request with XML-formatted payload to the specified URI without processing the response body.

public static Task PatchAsXmlAsync(this HttpRestClient client, string uri, object payload, CancellationToken cancellationToken = default)

Parameters

client HttpRestClient

The HttpRestClient instance to be used for sending the request.

uri string

The URI to which the request is sent.

payload object

The object to serialize as the XML-formatted HTTP request payload.

cancellationToken CancellationToken

A token for canceling the request (optional).

Returns

Task

A task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown if uri or payload is null.

HttpResponseException

Thrown if the response status code indicates a failure.

HttpRequestException

Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.

HttpContentException

Thrown if the response body is empty or its media type is not supported.

OperationCanceledException

Thrown if the operation is canceled via the cancellation token.

PatchAsXmlAsync<T>(HttpRestClient, string, object, CancellationToken)

Sends an asynchronous PATCH request with XML-formatted payload to the specified URI and returns the response body deserialized as the specified type.

public static Task<T?> PatchAsXmlAsync<T>(this HttpRestClient client, string uri, object payload, CancellationToken cancellationToken = default)

Parameters

client HttpRestClient

The HttpRestClient instance to be used for sending the request.

uri string

The URI to which the request is sent.

payload object

The object to serialize as the XML-formatted HTTP request payload.

cancellationToken CancellationToken

A token for canceling the request (optional).

Returns

Task<T>

A task that represents the asynchronous operation, with a result of the specified type.

Type Parameters

T

The type of the response object.

Exceptions

ArgumentNullException

Thrown if uri or payload is null.

HttpResponseException

Thrown if the response status code indicates a failure.

HttpRequestException

Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.

HttpContentException

Thrown if the response body is empty or its media type is not supported.

OperationCanceledException

Thrown if the operation is canceled via the cancellation token.

PostAsXmlAsync(HttpRestClient, string, object, CancellationToken)

Sends an asynchronous POST request with XML-formatted payload to the specified URI without processing the response body.

public static Task PostAsXmlAsync(this HttpRestClient client, string uri, object payload, CancellationToken cancellationToken = default)

Parameters

client HttpRestClient

The HttpRestClient instance to be used for sending the request.

uri string

The URI to which the request is sent.

payload object

The object to serialize as the XML-formatted HTTP request payload.

cancellationToken CancellationToken

A token for canceling the request (optional).

Returns

Task

A task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown if uri or payload is null.

HttpResponseException

Thrown if the response status code indicates a failure.

HttpRequestException

Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.

HttpContentException

Thrown if the response body is empty or its media type is not supported.

OperationCanceledException

Thrown if the operation is canceled via the cancellation token.

PostAsXmlAsync<T>(HttpRestClient, string, object, CancellationToken)

Sends an asynchronous POST request with XML-formatted payload to the specified URI.

public static Task<T?> PostAsXmlAsync<T>(this HttpRestClient client, string uri, object payload, CancellationToken cancellationToken = default)

Parameters

client HttpRestClient

The HttpRestClient instance to be used for sending the request.

uri string

The URI to which the request is sent.

payload object

The object to serialize as the XML-formatted HTTP request payload.

cancellationToken CancellationToken

A token for canceling the request (optional).

Returns

Task<T>

A task representing the asynchronous operation, returning a deserialized object of type T.

Type Parameters

T

The type of the object expected in the response.

Exceptions

ArgumentNullException

Thrown if uri or payload is null.

HttpResponseException

Thrown if the response status code indicates a failure.

HttpRequestException

Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.

HttpContentException

Thrown if the response body is empty or its media type is not supported.

OperationCanceledException

Thrown if the operation is canceled via the cancellation token.

PutAsXmlAsync(HttpRestClient, string, object, CancellationToken)

Sends an asynchronous PUT request with XML-formatted payload to the specified URI without processing the response body.

public static Task PutAsXmlAsync(this HttpRestClient client, string uri, object payload, CancellationToken cancellationToken = default)

Parameters

client HttpRestClient

The HttpRestClient instance to be used for sending the request.

uri string

The URI to which the request is sent.

payload object

The object to serialize as the XML-formatted HTTP request payload.

cancellationToken CancellationToken

A token for canceling the request (optional).

Returns

Task

A task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown if uri or payload is null.

HttpResponseException

Thrown if the response status code indicates a failure.

HttpRequestException

Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.

HttpContentException

Thrown if the response body is empty or its media type is not supported.

OperationCanceledException

Thrown if the operation is canceled via the cancellation token.

PutAsXmlAsync<T>(HttpRestClient, string, object, CancellationToken)

Sends an asynchronous PUT request with XML-formatted payload to the specified URI and returns the response body deserialized as the specified type.

public static Task<T?> PutAsXmlAsync<T>(this HttpRestClient client, string uri, object payload, CancellationToken cancellationToken = default)

Parameters

client HttpRestClient

The HttpRestClient instance to be used for sending the request.

uri string

The URI to which the request is sent.

payload object

The object to serialize as the XML-formatted HTTP request payload.

cancellationToken CancellationToken

A token for canceling the request (optional).

Returns

Task<T>

A task that represents the asynchronous operation, with a result of the specified type.

Type Parameters

T

The type of the response object.

Exceptions

ArgumentNullException

Thrown if uri or payload is null.

HttpResponseException

Thrown if the response status code indicates a failure.

HttpRequestException

Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.

HttpContentException

Thrown if the response body is empty or its media type is not supported.

OperationCanceledException

Thrown if the operation is canceled via the cancellation token.

SendAsXmlAsync(HttpRestClient, HttpMethod, string, object, CancellationToken)

Sends an asynchronous POST request with XML-formatted payload to the specified URI without processing the response body.

public static Task SendAsXmlAsync(this HttpRestClient client, HttpMethod method, string uri, object payload, CancellationToken cancellationToken = default)

Parameters

client HttpRestClient

The HttpRestClient instance to be used for sending the request.

method HttpMethod

The HTTP method to use for the request.

uri string

The URI to which the request is sent.

payload object

The object to serialize as the XML-formatted HTTP request payload.

cancellationToken CancellationToken

A token for canceling the request (optional).

Returns

Task

A task representing the asynchronous operation.

Exceptions

ArgumentNullException

Thrown if method, uri or payload is null.

HttpResponseException

Thrown if the response status code indicates a failure.

HttpRequestException

Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.

HttpContentException

Thrown if the response body is empty or its media type is not supported.

OperationCanceledException

Thrown if the operation is canceled via the cancellation token.

SendAsXmlAsync<T>(HttpRestClient, HttpMethod, string, object, CancellationToken)

Sends an asynchronous request with XML-formatted payload to the specified URI.

public static Task<T?> SendAsXmlAsync<T>(this HttpRestClient client, HttpMethod method, string uri, object payload, CancellationToken cancellationToken = default)

Parameters

client HttpRestClient

The HttpRestClient instance to be used for sending the request.

method HttpMethod

The HTTP method to use for the request.

uri string

The URI to which the request is sent.

payload object

The object to serialize as the XML-formatted HTTP request payload.

cancellationToken CancellationToken

A token for canceling the request (optional).

Returns

Task<T>

A task representing the asynchronous operation, returning a deserialized object of type T.

Type Parameters

T

The type of the object expected in the response.

Exceptions

ArgumentNullException

Thrown if method, uri or payload is null.

HttpResponseException

Thrown if the response status code indicates a failure.

HttpRequestException

Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.

HttpContentException

Thrown if the response body is empty or its media type is not supported.

OperationCanceledException

Thrown if the operation is canceled via the cancellation token.