JsonRpcClient 3.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package JsonRpcClient --version 3.0.0
NuGet\Install-Package JsonRpcClient -Version 3.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsonRpcClient" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonRpcClient --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JsonRpcClient, 3.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JsonRpcClient as a Cake Addin #addin nuget:?package=JsonRpcClient&version=3.0.0 // Install JsonRpcClient as a Cake Tool #tool nuget:?package=JsonRpcClient&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
JSON RPC 2.0 Client
Provides classes for creating JSON RPC 2.0 clients in C#.
Usage
Supposing the JSON RPC server defines the methods "add", "subtract", and "divide", expecting requests like this:
{
"id": 1,
"method": "add",
"params": [2, 3],
"jsonrpc": "2.0"
}
{
"id": 2,
"method": "subtract",
"params": [2, 3],
"jsonrpc": "2.0"
}
{
"id": 3,
"method": "divide",
"params": [3, 2],
"jsonrpc": "2.0"
}
Defining and using the corresponding client would look like this:
using System.Collections.Generic;
using System.Threading.Tasks;
using JsonRpcClient.Clients;
using Newtonsoft.Json;
namespace MathJsonRpcClient
{
public class MathClientDriver()
{
public void main(string[] args)
{
var client = new MathClient("http://localhost:5000/api/v1");
client.add(2, 3);
client.subtract(2, 3);
client.divide(3, 2);
}
}
public class MathClient : RpcHttpClient
{
public async Task<int> Add(int a, int b)
{
return await Call("add", new List<int>{a, b});
}
public async Task<int> Subtract(int a, int b)
{
return await Call("subtract", new List<int>{a, b});
}
public async Task<float> Divide(int a, int b)
{
return await Call("divide", new List<int>{a, b});
}
}
}
This client will form request bodies, send them to the server and return the result.
Errors
If the server responds with an error, an RpcError is thrown. There is an RpcError for each standard JSON RPC 2.0 error, each of them extends RpcError.
public void main(string[] args)
{
var client = new MathClient("http://localhost:5000/api/v1");
try
{
client.add("two", "three");
}
catch (InvalidParams e)
{
Console.WriteLine(e);
}
try
{
client.divide(0, 0);
}
catch (ServerError e)
{
Console.WriteLine(e);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.7.2
- Newtonsoft.Json (>= 13.0.1)
- System.Net.Http (>= 4.3.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.