Interface IJsonRpcClient
- Namespace
- Nerdbank.JsonRpc
- Assembly
- Nerdbank.JsonRpc.dll
Provides the client operations used by generated JSON-RPC proxy implementations.
public interface IJsonRpcClient
Remarks
This interface is public so source-generated code in consuming assemblies can reference it. Most application code should use JsonRpc or JsonRpcBatch directly. External implementations are not supported. Members may be added to this interface in future releases.
Properties
Serializer
Gets the serializer used to encode arguments and decode results.
JsonRpcSerializer Serializer { get; }
Property Value
Methods
CreateArguments(bool, int, CancellationToken)
Creates a serializer-neutral builder for named or positional arguments.
JsonRpcArgumentsBuilder CreateArguments(bool named, int count, CancellationToken cancellationToken = default)
Parameters
namedboolWhether to use named arguments.
countintThe exact number of arguments to write.
cancellationTokenCancellationTokenA token used when serializing all arguments.
Returns
- JsonRpcArgumentsBuilder
An argument builder using this client's serializer.
NotifyAsync(string, JsonRpcValue, CancellationToken)
Sends a notification with arguments already serialized using the channel's selected encoding.
ValueTask NotifyAsync(string method, JsonRpcValue arguments, CancellationToken cancellationToken)
Parameters
methodstringThe name of the remote method to invoke.
argumentsJsonRpcValueThe pre-serialized arguments payload.
cancellationTokenCancellationTokenA token whose cancellation is observed before the notification is posted.
Returns
- ValueTask
A task that completes when the notification has been accepted by the outbound channel.
Remarks
Consume the returned awaitable once. To share it, await it repeatedly, or compose it with other Tasks,
call AsTask() or Preserve() once and retain the returned awaitable instead of the original.
It may be backed by a pooled source that is recycled after consumption.
RequestAsync(string, JsonRpcValue, CancellationToken)
Sends a request with arguments already serialized using the channel's selected encoding.
ValueTask RequestAsync(string method, JsonRpcValue arguments, CancellationToken cancellationToken)
Parameters
methodstringThe name of the remote method to invoke.
argumentsJsonRpcValueThe pre-serialized arguments payload.
cancellationTokenCancellationTokenA token whose cancellation should be propagated to the remote endpoint.
Returns
- ValueTask
A task that completes when the remote endpoint sends its response.
Remarks
Consume the returned awaitable once. To share it, await it repeatedly, or compose it with other Tasks,
call AsTask() or Preserve() once and retain the returned awaitable instead of the original.
It may be backed by a pooled source that is recycled after consumption.
A remote RequestCancelled response throws OperationCanceledException.
Cancellation exceptions include cancellationToken only if it is canceled.
Unrequested remote cancellation has a message explaining that the remote party canceled processing without caller-requested cancellation.
The original remote error is retained as a JsonRpcException inner exception; other remote errors throw JsonRpcException.
RequestAsync<TResult>(string, JsonRpcValue, ITypeShape<TResult>, CancellationToken)
Sends a request with arguments already serialized using the channel's selected encoding.
ValueTask<TResult> RequestAsync<TResult>(string method, JsonRpcValue arguments, ITypeShape<TResult> resultShape, CancellationToken cancellationToken)
Parameters
methodstringThe name of the remote method to invoke.
argumentsJsonRpcValueThe pre-serialized arguments payload.
resultShapeITypeShape<TResult>The type shape describing
TResult.cancellationTokenCancellationTokenA token whose cancellation should be propagated to the remote endpoint.
Returns
- ValueTask<TResult>
A task that completes with the result returned by the remote endpoint.
Type Parameters
TResultThe expected result type.
Remarks
Consume the returned awaitable once. To share it, await it repeatedly, or compose it with other Tasks,
call AsTask() or Preserve() once and retain the returned awaitable instead of the original.
It may be backed by a pooled source that is recycled after consumption.
A remote RequestCancelled response throws OperationCanceledException.
Cancellation exceptions include cancellationToken only if it is canceled.
Unrequested remote cancellation has a message explaining that the remote party canceled processing without caller-requested cancellation.
The original remote error is retained as a JsonRpcException inner exception; other remote errors throw JsonRpcException.