Skip to content

JSON-RPC 2.0 provider for .NET Standard / .NET Core

License

Notifications You must be signed in to change notification settings

cuiopen/json-rpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

System.Data.JsonRpc

Provides support for serializing and deserializing JSON-RPC 2.0 messages.

NuGet package

Features

  • The serializer supports transparent usage of number and string message identifiers.
  • The serializer supports dynamic response type contracts when result data type depends on method parameters.

Specifics

The serializer is used as a stateful instance. Due to the JSON-RPC protocol nuances, deserializing a response requires more than only defining a response contract. Before deserializing a caller must specify a request identifier mapping to the corresponding method name (static bindings), or specify a request identifier mapping to the corresponding response contract (dynamic bindings). The serializer supports disposing for clearing all active bindings.

Compatibility

As recommended in the specification, the serializer provides backward compatibility for JSON-RPC 1.0 messages, limited to the intersection of JSON-RPC 1.0 and JSON-RPC 2.0 requirements and the API. As an example, the serializer can be used for serializing and deserializing Bitcoin protocol messages, according to the "Bitcoin Core APIs - Remote Procedure Calls" documentation. To enable JSON-RPC 1.0 compatibility, a caller must change the compatibility level on a serializer instance.

Examples

  • Communication with a JSON-RPC 2.0 server:
var serializer = new JsonRpcSerializer();
var request = new JsonRpcRequest("sum", 1L, new[] { 1, 2 });
var requestString = serializer.SerializeRequest(request);

// [Sending an HTTP request and storing a response string in the "responseString"]

serializer.ResponseContracts["sum"] = new JsonRpcResponseContract(typeof(int));
serializer.StaticResponseBindings[request.Id] = "sum";

var responseData = serializer.DeserializeResponseData(responseString);
var result = (int)responseData.Item.Message.Result;

About

JSON-RPC 2.0 provider for .NET Standard / .NET Core

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages