Class BaseClientService (1.60.0)

public abstract class BaseClientService : IClientService, IDisposable

A base class for a client service which provides common mechanism for all services, like serialization and GZip support. It should be safe to use a single service instance to make server requests concurrently from multiple threads. This class adds a special IHttpExecuteInterceptor to the ConfigurableMessageHandler execute interceptor list, which uses the given Authenticator. It calls to its applying authentication method, and injects the "Authorization" header in the request. If the given Authenticator implements IHttpUnsuccessfulResponseHandler, this class adds the Authenticator to the ConfigurableMessageHandler's unsuccessful response handler list.

Inheritance

object > BaseClientService

Namespace

GoogleApisServices

Assembly

Google.Apis.dll

Constructors

BaseClientService(Initializer)

protected BaseClientService(BaseClientService.Initializer initializer)

Constructs a new base client with the specified initializer.

Parameter
NameDescription
initializerBaseClientServiceInitializer

Fields

DefaultMaxUrlLength

public const uint DefaultMaxUrlLength = 2048

The default maximum allowed length of a URL string for GET requests.

Field Value
TypeDescription
uint

Properties

ApiKey

public string ApiKey { get; }

Gets the API-Key (DeveloperKey) which this service uses for all requests.

Property Value
TypeDescription
string

ApplicationName

public string ApplicationName { get; }

Gets the application name to be used in the User-Agent header.

Property Value
TypeDescription
string

BasePath

public abstract string BasePath { get; }

Gets the BasePath of the service.

Property Value
TypeDescription
string

BaseUri

public abstract string BaseUri { get; }

Gets the BaseUri of the service. All request paths should be relative to this URI.

Property Value
TypeDescription
string

BaseUriOverride

protected string BaseUriOverride { get; }

The BaseUri provided in the initializer, which may be null.

Property Value
TypeDescription
string

BatchPath

public virtual string BatchPath { get; }

The path used for batch operations.

Property Value
TypeDescription
string

BatchUri

public virtual string BatchUri { get; }

The URI used for batch operations.

Property Value
TypeDescription
string

Features

public abstract IList<string> Features { get; }

Gets the supported features by this service.

Property Value
TypeDescription
IListstring

GZipEnabled

public bool GZipEnabled { get; }

Gets or sets whether this service supports GZip.

Property Value
TypeDescription
bool

HttpClient

public ConfigurableHttpClient HttpClient { get; }

Gets the HTTP client which is used to create requests.

Property Value
TypeDescription
ConfigurableHttpClient

HttpClientInitializer

public IConfigurableHttpClientInitializer HttpClientInitializer { get; }

Gets a HTTP client initializer which is able to custom properties on ConfigurableHttpClient and ConfigurableMessageHandler.

Property Value
TypeDescription
IConfigurableHttpClientInitializer

Name

public abstract string Name { get; }

Gets the service name.

Property Value
TypeDescription
string

Serializer

public ISerializer Serializer { get; }

Gets the Serializer used by this service.

Property Value
TypeDescription
ISerializer

Methods

CreateBackOffHandler()

protected virtual BackOffHandler CreateBackOffHandler()

Creates the back-off handler with ExponentialBackOff. Overrides this method to change the default behavior of back-off handler (e.g. you can change the maximum waited request's time span, or create a back-off handler with you own implementation of IBackOff).

Returns
TypeDescription
BackOffHandler

DeserializeError(HttpResponseMessage)

public virtual Task<RequestError> DeserializeError(HttpResponseMessage response)

Deserializes an error response into a RequestError object.

Parameter
NameDescription
responseHttpResponseMessage
Returns
TypeDescription
TaskRequestError
Exceptions
TypeDescription
GoogleApiException

If no error is found in the response.

DeserializeResponse<T>(HttpResponseMessage)

public virtual Task<T> DeserializeResponse<T>(HttpResponseMessage response)

Deserializes a response into the specified object.

Parameter
NameDescription
responseHttpResponseMessage
Returns
TypeDescription
Task
Type Parameter
NameDescription
T

Dispose()

public virtual void Dispose()

SerializeObject(object)

public virtual string SerializeObject(object obj)

Serializes an object into a string representation.

Parameter
NameDescription
objobject
Returns
TypeDescription
string

SetRequestSerailizedContent(HttpRequestMessage, object)

public void SetRequestSerailizedContent(HttpRequestMessage request, object body)

Sets the content of the request by the given body and the this service's configuration. First the body object is serialized by the Serializer and then, if GZip is enabled, the content will be wrapped in a GZip stream, otherwise a regular string stream will be used.

Parameters
NameDescription
requestHttpRequestMessage
bodyobject

Extension Method