HttpRestClientXmlExtensions Class

Namespace
Kampute.HttpClient.DataContract
Assembly
  • Kampute.HttpClient.DataContract.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, DataContractSerializerSettings)

Configures the HttpRestClient to accept XML responses by adding or updating a XmlContentDeserializer in its response deserializers collection.
public static XmlContentDeserializer AcceptXml(this HttpRestClient client, DataContractSerializerSettings settings = null)

Parameters

client HttpRestClient
The HttpRestClient instance to configure.
settings DataContractSerializerSettings optional
The DataContractSerializerSettings to use for deserializing XML responses. if null, default settings will be used.

Returns

XmlContentDeserializer
The XmlContentDeserializer used for XML content deserialization.

Remarks

If the client already has a XmlContentDeserializer, this method updates its options with the provided settings. Otherwise, it adds a new XmlContentDeserializer with the specified options to the client's response deserializers.

GetXmlSerializerSettings(this HttpRestClient)

Retrieves the settings used by the HttpRestClient when serializing payloads as XML.
public static DataContractSerializerSettings GetXmlSerializerSettings(this HttpRestClient client)

Parameters

client HttpRestClient
The HttpRestClient instance to query.

Returns

DataContractSerializerSettings
The DataContractSerializerSettings if set; otherwise, null.

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.

SetXmlSerializerSettings(this HttpRestClient, DataContractSerializerSettings)

Configures the HttpRestClient to use the specified settings when serializing payloads as XML.
public static void SetXmlSerializerSettings(this HttpRestClient client, DataContractSerializerSettings settings)

Parameters

client HttpRestClient
The HttpRestClient instance to configure.
settings DataContractSerializerSettings
The DataContractSerializerSettings to use for serializing payload as XML. If null, default settings will be used.