HttpRestClientXmlExtensions Class

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

Definition

Provides extension methods for HttpRestClient to support XML-based HTTP operations.
public static class HttpRestClientXmlExtensions
Inheritance
  • object
  • HttpRestClientXmlExtensions

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(this 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<T>(this 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)

Type Parameters

T
The type of the response object.

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 optional
A token for canceling the request (optional).

Returns

Task<T>
A task that represents the asynchronous operation, with a result of the specified type.

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(this 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 optional
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>(this 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)

Type Parameters

T
The type of the object expected in the response.

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 optional
A token for canceling the request (optional).

Returns

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

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(this 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 optional
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>(this 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)

Type Parameters

T
The type of the response object.

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 optional
A token for canceling the request (optional).

Returns

Task<T>
A task that represents the asynchronous operation, with a result of the specified type.

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(this 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 optional
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.

SendAsXmlAsync<T>(this 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)

Type Parameters

T
The type of the object expected in the response.

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 optional
A token for canceling the request (optional).

Returns

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

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(this 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 optional
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.