# Class BaseClientService (1.73.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [1.73.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.BaseClientService)
- [1.69.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.69.0/Google.Apis.Services.BaseClientService)
- [1.68.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.68.0/Google.Apis.Services.BaseClientService)
- [1.60.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.60.0/Google.Apis.Services.BaseClientService)
- [1.59.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.59.0/Google.Apis.Services.BaseClientService)
- [1.55.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.55.0/Google.Apis.Services.BaseClientService)
- [1.50.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.50.0/Google.Apis.Services.BaseClientService)

    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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExecuteInterceptor) to the
[ConfigurableMessageHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpUnsuccessfulResponseHandler), this
class adds the Authenticator to the [ConfigurableMessageHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableMessageHandler)'s unsuccessful
response handler list.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> BaseClientService

## Implements

[IClientService](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.IClientService), [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Apis.Services](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services)

## Assembly

Google.Apis.dll

## Constructors

### BaseClientService(Initializer)

    protected BaseClientService(BaseClientService.Initializer initializer)

Constructs a new base client with the specified initializer.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `initializer` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.BaseClientServicehttps://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.BaseClientService.Initializer` |

## Fields

### DefaultMaxUrlLength

    public const uint DefaultMaxUrlLength = 2048

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

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.uint32` |   |

## Properties

### ApiKey

    public string ApiKey { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### ApplicationName

    public string ApplicationName { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### BasePath

    public abstract string BasePath { get; }

Gets the BasePath of the service.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### BaseUri

    public abstract string BaseUri { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### BaseUriOverride

    protected string BaseUriOverride { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### BatchPath

    public virtual string BatchPath { get; }

The path used for batch operations.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### BatchUri

    public virtual string BatchUri { get; }

The URI used for batch operations.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### Features

    public abstract IList<string> Features { get; }

Gets the supported features by this service.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://learn.microsoft.com/dotnet/api/system.string` |   |

### GZipEnabled

    public bool GZipEnabled { get; }

Gets or sets whether this service supports GZip.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### HttpClient

    public ConfigurableHttpClient HttpClient { get; }

Gets the HTTP client which is used to create requests.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableHttpClient` |   |

### HttpClientInitializer

    public IConfigurableHttpClientInitializer HttpClientInitializer { get; }

Gets a HTTP client initializer which is able to custom properties on
[ConfigurableHttpClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableHttpClient) and
[ConfigurableMessageHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableMessageHandler).

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IConfigurableHttpClientInitializer` |   |

### HttpClientTimeout

    public TimeSpan? HttpClientTimeout { get; }

The timeout to set on [HttpClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.BaseClientService#Google_Apis_Services_BaseClientService_HttpClient) instances used by the service.
May be null, in which case the default timeout values on [HttpClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.BaseClientService#Google_Apis_Services_BaseClientService_HttpClient) instances
used by this service will be left unchanged.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### Name

    public abstract string Name { get; }

Gets the service name.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### Serializer

    public ISerializer Serializer { get; }

Gets the Serializer used by this service.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.ISerializer` |   |

### UniverseDomain

    public string UniverseDomain { get; set; }

The universe domain to connect to, or null to use the default universe domain,
which may be configured via the Google.Apis.Services.BaseClientService.UniverseDomainEnvironmentVariable .

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

**Remarks**
[UniverseDomain](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.BaseClientService#Google_Apis_Services_BaseClientService_UniverseDomain) is used to build the endpoint to connect to, unless [BaseUriOverride](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.BaseClientService#Google_Apis_Services_BaseClientService_BaseUriOverride)
is set, in which case [BaseUriOverride](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.BaseClientService#Google_Apis_Services_BaseClientService_BaseUriOverride) will be used without further modification.

## Methods

### CreateBackOffHandler()

    protected virtual BackOffHandler CreateBackOffHandler()

Creates the back-off handler with [ExponentialBackOff](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.IBackOff)).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.BackOffHandler` |   |

### DeserializeError(HttpResponseMessage)

    public virtual Task<RequestError> DeserializeError(HttpResponseMessage response)

Deserializes an error response into a [RequestError](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests.RequestError) object.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `response` | `https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests.RequestError` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.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** ||
|---|---|
| **Name** | **Description** |
| `response` | `https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1` |   |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` |   |

### Dispose()

    public virtual void Dispose()

### GetEffectiveUri(string, string)

    protected string GetEffectiveUri(string explicitUri, string defaultUri)

Gets the effective URI taking into account the [UniverseDomain](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.BaseClientService#Google_Apis_Services_BaseClientService_UniverseDomain) and the value of
the Google.Apis.Services.BaseClientService.UniverseDomainEnvironmentVariable.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `explicitUri` | `https://learn.microsoft.com/dotnet/api/system.string` An explicit URI. May be null. |
| `defaultUri` | `https://learn.microsoft.com/dotnet/api/system.string` A default URI. May be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` | - `explicitUri` if not null. - Otherwise, if Google.Apis.Services.BaseClientService.EffectiveConfiguredUniverseDomain is not null, the result of replacing Google.Apis.Services.BaseClientService.DefaultUniverseDomain with Google.Apis.Services.BaseClientService.EffectiveConfiguredUniverseDomain in `defaultUri`. |

### SerializeObject(object)

    public virtual string SerializeObject(object obj)

Serializes an object into a string representation.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `obj` | `https://learn.microsoft.com/dotnet/api/system.object` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.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** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage` |
| `body` | `https://learn.microsoft.com/dotnet/api/system.object` |

## Extension Method

[Utilities.ThrowIfNull\<T\>(T, string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Utilities#Google_Apis_Util_Utilities_ThrowIfNull__1___0_System_String_)