Class WebServerInvoker
A class for communicating over the Internet to MyGeotab. This class is thread safe.
public class WebServerInvoker : IWebServerInvoker
  - Inheritance
 - 
      
      WebServerInvoker
 
- Implements
 
- Derived
 
- Inherited Members
 
Remarks
The maximum number of concurrent connections per server is 64, provided by the default HttpClientHandler. It can be increased/decreased by providing a custom instance of HttpMessageHandler.
Constructors
WebServerInvoker(string, int?)
Initializes a new instance of the WebServerInvoker class.
public WebServerInvoker(string url, int? timeout = null)
  Parameters
WebServerInvoker(string, int?, HttpMessageHandler?, ApiClientConfiguration?)
Initializes a new instance of the WebServerInvoker class.
public WebServerInvoker(string url, int? timeout, HttpMessageHandler? overrideHttpMessageHandler, ApiClientConfiguration? apiClientConfiguration = null)
  Parameters
urlstringThe URL.
timeoutint?The timeout in milliseconds or default 5 minutes.
overrideHttpMessageHandlerHttpMessageHandlerThe HttpMessageHandler for overriding of the default shared httpClient (max connection pool size 64).
apiClientConfigurationApiClientConfigurationThe ApiClientConfiguration provided by the API client for custom configurations.
Fields
DefaultTimeOut
The default time out in milliseconds.
protected const int DefaultTimeOut = 300000
  Field Value
KeyOfResponseJsonRpcErrorData
The key to access the JsonRpcErrorData from response exception
public const string KeyOfResponseJsonRpcErrorData = "JsonRpcErrorData"
  Field Value
MaximumConnectionsPerServer
The maximum number of concurrent connections (per server endpoint) allowed when making requests using an HttpClient object The explicit connection pool size of 64
public const int MaximumConnectionsPerServer = 64
  Field Value
Properties
ParallelDownloadSize
Gets or sets the size (in bytes) at which parallel downloading will be used. Value is 100GB.
public int ParallelDownloadSize { get; set; }
  Property Value
- int
 size in bytes
SharedHttpClient
Gets the shared HttpClient.
protected virtual HttpClient SharedHttpClient { get; }
  Property Value
- HttpClient
 The HttpClient.
Timeout
Gets the timeout.
public TimeSpan Timeout { get; }
  Property Value
- TimeSpan
 The timeout.
Url
Gets the URL.
public string Url { get; }
  Property Value
- string
 The URL.
Methods
CheckForError(string, Exception?, JsonRpcErrorCode?, JsonRpcErrorData?)
Check JSON error.
protected virtual Exception? CheckForError(string message, Exception? innerException, JsonRpcErrorCode? errorCode, JsonRpcErrorData? errorData)
  Parameters
messagestringThe error message.
innerExceptionExceptionThe inner exception.
errorCodeJsonRpcErrorCode?The JsonRpcErrorCode for JSON-RPC error type that occurred.
errorDataJsonRpcErrorDataPrimitive or Structured value that contains additional information about the error.
Returns
- Exception
 The Exception object.
CreateParametersDictionary(params object?[])
Creates a dictionary from a set of provided parameter names and values.
public static Dictionary<string, object?> CreateParametersDictionary(params object?[] args)
  Parameters
argsobject[]An even number of alternating parameter names and values.
Returns
- Dictionary<string, object>
 A dictionary of parameters.
Exceptions
- ArgumentException
 There must be an even number of arguments to represent name and value pairs.
DownloadFileAsync(string, Stream, object?, int, CancellationToken)
Download a file to a stream.
public Task DownloadFileAsync(string method, Stream outputStream, object? parameters = null, int retryLimit = 3, CancellationToken cancellationToken = default)
  Parameters
methodstringThe method to invoke.
outputStreamStreamThe stream to which the binary data will be copied.
parametersobjectParameters to pass into the method: an array of objects in the order of the invoked method's parameter list, or IDictionary containing the named values to pass into the method, or an anonymous object with corresponding parameter values, for instance: new {username = "ivant@gmail.com", password = "123"}.
retryLimitintThe number of times the call will be retried. Use 1 for no retries.
cancellationTokenCancellationTokenThe CancellationToken used to signal that the request should be canceled.
Returns
GetJsonResponseAsync<T>(Dictionary<string, object>, string, CancellationToken, string?)
Make an API call and returns result of JToken.
protected virtual Task<JsonResponse<T>?> GetJsonResponseAsync<T>(Dictionary<string, object> jsonRequest, string requestUrl, CancellationToken cancellationToken, string? traceId = null)
  Parameters
jsonRequestDictionary<string, object>API Call payload.
requestUrlstringRequest url.
cancellationTokenCancellationTokenCancellation token.
traceIdstringtraceId of httpcontext
Returns
- Task<JsonResponse<T>>
 The JsonResponse<T>.
Type Parameters
TThe object type to deserialize to and return.
GetRpcError<T>(string, JsonResponse<T>?)
Generates an Exception based on the JSON-RPC response error.
protected virtual Exception? GetRpcError<T>(string method, JsonResponse<T>? jsonResponse)
  Parameters
methodstringThe name of the api that is invoked by the invoker.
jsonResponseJsonResponse<T>The JSON-RPC response from the api.
Returns
- Exception
 The Exception object, wraps an inner WebServerInvokerJsonException.
Type Parameters
TThe object type to deserialize to and return.
HttpDownloadFile(string, string, long?, object?)
Download a file.
[Obsolete("Use HttpDownloadFileAsync")]
public virtual void HttpDownloadFile(string method, string path, long? fileSize = null, object? parameters = null)
  Parameters
methodstringThe method to invoke.
pathstringThe save location and file name.
fileSizelong?The size of the file to transfer. If known and if it is large the file will be downloaded in parallel streams.
parametersobjectParameters to pass into the method: an array of objects in the order of the invoked method's parameter list, or IDictionary containing the named values to pass into the method, or an anonymous object with corresponding parameter values, for instance: new {username = "ivant@gmail.com", password = "123"}.
Exceptions
- ArgumentNullException
 Path cannot be null.
HttpDownloadFileAsync(string, string?, long?, object?, in CancellationToken)
Download a file.
public Task HttpDownloadFileAsync(string method, string? path, long? fileSize = null, object? parameters = null, in CancellationToken cancellationToken = default)
  Parameters
methodstringThe method to invoke.
pathstringThe save location and file name.
fileSizelong?The size of the file to transfer. If known and if it is large the file will be downloaded in parallel streams.
parametersobjectParameters to pass into the method: an array of objects in the order of the invoked method's parameter list, or IDictionary containing the named values to pass into the method, or an anonymous object with corresponding parameter values, for instance: new {username = "ivant@gmail.com", password = "123"}.
cancellationTokenCancellationTokenThe CancellationToken used to signal that the request should be cancelled.
Returns
- Task
 Task.
Exceptions
- ArgumentNullException
 Exception if path is null.
HttpUploadFileAsync<T>(string, string, string, string, object, in CancellationToken)
Upload a file to the specified URL.
public virtual Task<JsonResponse<T>?> HttpUploadFileAsync<T>(string uploadUrl, string file, string contentType, string method, object parameters, in CancellationToken cancellationToken = default)
  Parameters
uploadUrlstringThe URL.
filestringThe file.
contentTypestringType of the content.
methodstringThe method.
parametersobjectThe parameters.
cancellationTokenCancellationTokenThe CancellationToken used to signal that the request should be cancelled.
Returns
- Task<JsonResponse<T>>
 The optional method results from the provided method.
Type Parameters
TThe object type to deserialize to and return.
HttpUploadFile<T>(string, string, string, string, object)
Upload a file to the specified URL.
[Obsolete("Use HttpUploadFileAsync rather")]
public JsonResponse<T>? HttpUploadFile<T>(string uploadUrl, string file, string contentType, string method, object parameters)
  Parameters
uploadUrlstringThe URL.
filestringThe file.
contentTypestringType of the content.
methodstringThe method.
parametersobjectThe parameters.
Returns
- JsonResponse<T>
 The optional method results from the provided method.
Type Parameters
TThe object type to deserialize to and return.
InvokeAsync<T>(string, object?, CancellationToken)
Asynchronously invoke a call to the specified method.
public virtual Task<T?> InvokeAsync<T>(string method, object? parameters = null, CancellationToken cancellationToken = default)
  Parameters
methodstringMethod to invoke.
parametersobjectAn anonymous object used as the parameters to pass into the method with corresponding parameter values, for instance: new {username = "ivant@gmail.com", password = "123"}.
cancellationTokenCancellationTokenThe CancellationToken used to signal that the request should be cancelled.
Returns
Type Parameters
TThe object type to deserialize to and return.
InvokeAsync<T>(string, string?, object?, CancellationToken)
Asynchronously executes the method.
public Task<T?> InvokeAsync<T>(string method, string? traceId, object? parameters = null, CancellationToken cancellationToken = default)
  Parameters
methodstringMethod to invoke.
traceIdstringtraceId of httpcontext
parametersobjectParameters to pass into the method: an array of objects in the order of the invoked method's parameter list, or IDictionary containing the named values to pass into the method, or an anonymous object with corresponding parameter values, for instance: new {username = "ivant@gmail.com", password = "123"}.
cancellationTokenCancellationTokenThe CancellationToken used to signal that the request should be cancelled.
Returns
- Task<T>
 The Task<TResult> containing the result of the invoke operation converted to the return Type if provided.
Type Parameters
TThe object type to deserialize to and return.
Invoke<T>(string, object?)
Synchronously executes the method.
[Obsolete("Sync code is not efficient - use await invoker.InvokeAsync(..")]
public T? Invoke<T>(string method, object? parameters = null)
  Parameters
methodstringMethod to invoke.
parametersobjectParameters to pass into the method: an array of objects in the order of the invoked method's parameter list, or IDictionary containing the named values to pass into the method, or an anonymous object with corresponding parameter values, for instance: new {username = "ivant@gmail.com", password = "123"}.
Returns
- T
 Result of the invoke operation converted to the return Type if provided.
Type Parameters
TThe object type to deserialize to and return.
JsonToObjectAsync<T>(Stream)
Deserializes the JsonResponse<T> from the Stream.
protected virtual Task<JsonResponse<T>?> JsonToObjectAsync<T>(Stream contentStream)
  Parameters
contentStreamStreamThe stream to deserialize from.
Returns
- Task<JsonResponse<T>>
 The JsonResponse<T> from the Stream along with any errors.
Type Parameters
TThe T.
ThrowResponseFailed(HttpStatusCode, Exception, string?)
Throws new instance of the HttpRequestException class with inner ResponseFailException.
public static void ThrowResponseFailed(HttpStatusCode statusCode, Exception innerException, string? url = null)
  Parameters
statusCodeHttpStatusCodeThe status code.
innerExceptionExceptionThe inner Exception.
urlstringThe url.
Exceptions
- HttpRequestException
 The instance of the HttpRequestException.
- ArgumentNullException
 The instance of the ArgumentNullException if innerException is undefined.
ToJson(object)
Convert object to JSON string.
protected virtual string ToJson(object obj)
  Parameters
objobjectThe object to be converted.
Returns
- string
 The JSON string result.
ToJsonContent(object)
Gets JsonContent wrapped serialization target.
protected virtual JsonContent ToJsonContent(object serializationTarget)
  Parameters
serializationTargetobjectThe object for seralization.
Returns
UploadFileAsync(Stream, string, string, string, object, CancellationToken)
Upload a file.
public Task UploadFileAsync(Stream stream, string fileName, string contentType, string method, object parameters, CancellationToken cancellationToken = default)
  Parameters
streamStreamThe Stream of binary data to upload.
fileNamestringThe file name including extension.
contentTypestringType of the content.
methodstringThe method.
parametersobjectThe parameters.
cancellationTokenCancellationTokenThe CancellationToken used to signal that the request should be cancelled.
Returns
- Task
 The optional method results from the provided method.