Class JsonRpcMessage
- Namespace
- StreamJsonRpc.Protocol
- Assembly
- StreamJsonRpc.dll
The base class for a JSON-RPC request or response.
[DataContract]
[KnownType(typeof(JsonRpcRequest))]
[KnownType(typeof(JsonRpcResult))]
[KnownType(typeof(JsonRpcError))]
[MessagePackConverter(typeof(NerdbankMessagePackFormatter.JsonRpcMessageConverter))]
[GenerateShape]
public abstract class JsonRpcMessage
- Inheritance
-
JsonRpcMessage
- Derived
- Inherited Members
Properties
Version
Gets or sets the version of the JSON-RPC protocol that this message conforms to.
[DataMember(Name = "jsonrpc", Order = 0, IsRequired = true)]
[JsonPropertyName("jsonrpc")]
[JsonPropertyOrder(0)]
[JsonRequired]
[PropertyShape(Name = "jsonrpc", Order = 0)]
public string Version { get; set; }
Property Value
- string
Defaults to "2.0".
Methods
TryGetTopLevelProperty<T>(string, out T)
Retrieves a top-level property from an incoming message that is an extension to the JSON-RPC specification.
public virtual bool TryGetTopLevelProperty<T>(string name, out T value)
Parameters
name
stringThe name of the top-level property.
value
TReceives the deserialized value if the IJsonRpcMessageFormatter supports reading such properties and the property is present in the message. Otherwise, this parameter is set to its default value.
Returns
- bool
true if the IJsonRpcMessageFormatter supports this extensibility and the property was present on the message; otherwise false.
Type Parameters
T
The type to deserialize the value as, if it is present.
Exceptions
- InvalidOperationException
May be thrown when called on an outbound message.
- ArgumentNullException
Thrown when
name
is null.- ArgumentException
Thrown when
name
is reserved by the JSON-RPC spec.
TrySetTopLevelProperty<T>(string, T)
Sets a top-level property in the message that is an extension to JSON-RPC specification.
public virtual bool TrySetTopLevelProperty<T>(string name, T value)
Parameters
name
stringThe name of the property. This should not collide with any property defined by the JSON-RPC specification.
value
TThe value for the property.
Returns
Type Parameters
T
The type of value to be serialized.
Exceptions
- InvalidOperationException
May be thrown when called on an inbound message.
- ArgumentNullException
Thrown when
name
is null.- ArgumentException
Thrown when
name
is reserved by the JSON-RPC spec.