Skip to content

Event as Request from JSON Rpc Server #950

Closed

Description

Good afternoon!

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:

{
   "jsonrpc" :  "2.0" ,
   "method" :  "Event.eventOccurred" ,
   "params" : { ... }
   }
}

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)?

Thanks in advance!

Activity

  1. AArnott commented on Jul 24, 2023

    @AArnott
    Member

    This response looks like this:

    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.

  2. locked and limited conversation to collaborators on Jul 24, 2023
  3. converted this issue into a discussion #951 on Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions