You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using your package for implementing a json rpc client which connects to a json rpc server (json rpc server is provided by an external client). I am using your package for connecting to the server an executing the methods it provides. So far so good it works like a charm for simple calls.
However, the server has a special functionality where he sends a response when an event is raised inside him. I cannot subscribe to this response and I neither can use NotifyAsync method since this method is not a valid method to call in my server methods. This response looks like this:
For managing this special use case I am using a method provided by your package like follows:
jsonRpc.AddLocalRpcMethod("Event.eventOccurred", "Here I will have an async delegate");
As I understand this AddLocalRpcMethod will create a local method to execute when called. I do not know if maybe I am missunderstanding the method or maybe my implementation is not correct but this method seems to never be called which means my async delegate is not executed and my flow cannot continue.
Am I doing a proper approach using AddLocalRpcMethod for my use case?
Should I do this in a different way? If yes... How can I manage this?
Is it possible to receive messages throught the socket without asking for them pointing to an "endpoint" (this would be this case if I am not wrong)?
I'm confused by your terminology. The JSON object you share is not a response. It is a notification. Responses do not include method names.
I neither can use NotifyAsync method since this method is not a valid method to call in my server methods.
I don't understand this either, because in fact RPC server methods can call NotifyAsync just fine. But as you don't implement the party you are calling a server, and that remote party is the one I believe is sending the notification, I don't know why the party receiving the notification would ever have need to call NotifyAsync.
jsonRpc.AddLocalRpcMethod ought to work, provided the signature of the delegate you provide matches the shape of the params property per the JSON-RPC spec. If it doesn't match, it'll just drop the notification without invoking your delegate. Turning on logging via JsonRpc.TraceSource would allow you to see if such an error is happening.
Another option is to declare a method on a class, and pass an instance of that class is a local target object. That will let the remote party invoke public methods on your locally defined class. Since the method name on this notification isn't a valid C# method name, you can apply the [JsonRpcMethod("Event.eventOccurred")] attribute to the method so that it will be invoked as expected. But again, the same method signature requirement applies, and the logs can help you diagnose this.
Activity
AArnott commentedon Jul 24, 2023
I'm confused by your terminology. The JSON object you share is not a response. It is a notification. Responses do not include method names.
I don't understand this either, because in fact RPC server methods can call
NotifyAsyncjust fine. But as you don't implement the party you are calling a server, and that remote party is the one I believe is sending the notification, I don't know why the party receiving the notification would ever have need to callNotifyAsync.jsonRpc.AddLocalRpcMethodought to work, provided the signature of the delegate you provide matches the shape of theparamsproperty per the JSON-RPC spec. If it doesn't match, it'll just drop the notification without invoking your delegate. Turning on logging viaJsonRpc.TraceSourcewould allow you to see if such an error is happening.Another option is to declare a method on a class, and pass an instance of that class is a local target object. That will let the remote party invoke public methods on your locally defined class. Since the method name on this notification isn't a valid C# method name, you can apply the
[JsonRpcMethod("Event.eventOccurred")]attribute to the method so that it will be invoked as expected. But again, the same method signature requirement applies, and the logs can help you diagnose this.