Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call method without parameters #134

Closed
BuilovAlexey opened this issue Aug 31, 2015 · 6 comments
Closed

Call method without parameters #134

BuilovAlexey opened this issue Aug 31, 2015 · 6 comments

Comments

@BuilovAlexey
Copy link

I want call method from server

        [JsonRpcMethod] 
        public string GetWindowsUserName()
        {
            return System.Environment.UserName;
        }

I use https://github.com/Astn/JSON-RPC.NET framework for server.

In client i need call method without parameters:

        Json::Value params;
        params = Json::Value::null;
        Value methodResult = clientNew.CallMethod("GetWindowsUserName", params);

but i get
Exception -32602 : INVALID_PARAMS: Invalid method parameters (invalid name and/or type) recognised: Invalid params, data: "The number of parameters could not be counted"
With use "params = Json::nullValue" i get same result.
How i can to call method without parameters?

P.s. when i call method with parameters I get normal result.

@cinemast
Copy link
Owner

Sounds to me like an error on the side of JSON-RPC.NET. If there are no parameters passed, the params field can be ommited. It is also in the JSON-RPC specification: http://www.jsonrpc.org/specification

You should raise an issue at JSON-RPC.NEt about this.

@BuilovAlexey
Copy link
Author

ok, but if server will by libjson-rpc-cpp server, what i must to do, to call method without parameters?
Will my example work? or what value must have "params", if method "GetWindowsUserName" haven't parameters?

  Json::Value params;
  params = Json::Value::null;
  Value methodResult = clientNew.CallMethod("GetWindowsUserName", params);

@BuilovAlexey
Copy link
Author

A try call method without parameters:

    Json::Value params;
    params = Json::Value::null;
    HttpClient httpClient("http://localhost:3333/");
    Client clientNew(httpClient);
    Value methodResult = clientNew.CallMethod("GetWindowsUserName", params);

In server i get this request message:
{"id":1,"jsonrpc":"2.0","method":"GetWindowUserName"}
And whis request can't parse JSON-RPC.NET lib.
i find here http://support.mashery.com/docs/read/mashery_api/20/JSON_RPC example without parameters. in this case json request:
{ "jsonrpc": "2.0", "method": "test.hello", "params": [], "id": 1 }
but i think it's incorrect example....

I test this case:

httpClient.SendRPCMessage("{\"jsonrpc\":\"2.0\",\"method\":\"GetWindowsUserName\",\"params\":[],\"id\":1}",methodResult);

and get normal response with result of this method.

but, in here http://www.jsonrpc.org/specification i find this example:

a Notification:
--> {"jsonrpc": "2.0", "method": "update", "params": [1,2,3,4,5]}
--> {"jsonrpc": "2.0", "method": "foobar"}
rpc call of non-existent method:
--> {"jsonrpc": "2.0", "method": "foobar", "id": "1"}

hm... okey i think i need fix fix and rebuild .net json rpc project... fix to parse message when params has no value.

@cinemast
Copy link
Owner

cinemast commented Sep 1, 2015

Yes, it is an error in the JSON-RPC.NET framework. You really should raise an issue there with your findings and reference this issue here.

@BuilovAlexey
Copy link
Author

JSON-RPC.NET last commit was half year ago.. and author don't answer to users by last some issues. okey may be i will raise issue, but i haven't time for wait bug fix.

@BuilovAlexey
Copy link
Author

omg... they fix this bug in one of the last commits, but don't refresh nuget package...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants