HttpRestClientXmlExtensions Class

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

Definition

Provides extension methods for HttpRestClient that register an XML formatter and send XML payloads.
public static class HttpRestClientXmlExtensions
Inheritance
  • object
  • HttpRestClientXmlExtensions

Remarks

UseXml(this HttpRestClient, Action<XmlFormatter>) registers an XmlFormatter, which lets the client read XML responses and advertise XML in the Accept header. The send helpers write their payloads with the registered XmlFormatter, or with a new one with default settings if none is registered.

Methods

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 client, 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, or server certificate validation.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token, or if the timeout of the underlying HttpClient elapses.

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 client, 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, or server certificate validation.
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, or if the timeout of the underlying HttpClient elapses.

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 client, 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, or server certificate validation.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token, or if the timeout of the underlying HttpClient elapses.

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 client, 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, or server certificate validation.
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, or if the timeout of the underlying HttpClient elapses.

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 client, 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, or server certificate validation.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token, or if the timeout of the underlying HttpClient elapses.

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 client, 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, or server certificate validation.
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, or if the timeout of the underlying HttpClient elapses.

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

Sends an asynchronous 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 client, 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, or server certificate validation.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token, or if the timeout of the underlying HttpClient elapses.

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 client, 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, or server certificate validation.
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, or if the timeout of the underlying HttpClient elapses.

UseXml(this HttpRestClient, Action<XmlFormatter>)

Registers an XmlFormatter with the client, or updates the registered one.
public static XmlFormatter UseXml(this HttpRestClient client, Action<XmlFormatter> configure = null)

Parameters

client HttpRestClient
The HttpRestClient instance to configure.
configure Action<XmlFormatter> optional
An action that sets the options of the formatter, such as XmlFormatter.Serializer (optional).

Returns

XmlFormatter
The registered XmlFormatter.

Exceptions

ArgumentNullException
Thrown if client is null.

Remarks

If the client already has an XmlFormatter, this method passes that formatter to configure. Otherwise, it adds a new XmlFormatter to HttpRestClient.ContentFormatters and passes the new one.