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

How do you get returned data from the request? #2

Closed
DNATechAdmin opened this issue Jan 4, 2018 · 5 comments
Closed

How do you get returned data from the request? #2

DNATechAdmin opened this issue Jan 4, 2018 · 5 comments

Comments

@DNATechAdmin
Copy link

 var client = new Spooky.Json20.JsonRpcHttpClient(new Uri("http://www.myserver.com/mathservice"));
    var answer = await client.Invoke<int>
    (
	    "add", 
	    new Dictionary<string, object>()
	    {
    		{ "a", 4 },
	    	{ "b", 6 }
	    }
    ).ConfigureAwait(false);

This is a great example on implementing your code. Does client.Invoke only ever return an int?
What do we do to access the underlying data?

@Yortw
Copy link
Owner

Yortw commented Jan 5, 2018

Hi,

client.Invoke returns the response from the server deserialised as the generic type specified after Invoke, so when it says

    client.Invoke<int>

The <int> part says we expect an integer returned from the server, and the result of the Invoke call will be an integer. You ask for a different type of result by changing the generic argument;

  //Request a string
    var greeting = await client.Invoke<string>
    (
	    "GetGreeting", 
	    new Dictionary<string, object>()
	    {
    		{ "Language", "English" },
	    	{ "Name", "Yort" }
	    }
    ).ConfigureAwait(false);


  //Request a 'customer' where 'Customer' is  class you've defined.
    var foundCustomer = await client.Invoke<Customer>
    (
	    "GetCustomerById", 
	    new Dictionary<string, object>()
	    {
    		{ "Id", 1234 },
	    }
    ).ConfigureAwait(false);

If the server returns an error, or a network error occurs etc. then an exception is thrown. So you either get the type you asked for as the result, or an exception. There is no access to 'underlying data' as the point of the library is to abstract away the transport/protocol details. You either get a valid response from the server or an exception.

I hope that helps.

@DNATechAdmin
Copy link
Author

DNATechAdmin commented Jan 5, 2018 via email

@Yortw
Copy link
Owner

Yortw commented Jan 5, 2018

Wow, that's annoying they didn't follow the spec. Forks are welcome!

If it's going to be on Github then just in the Readme.md is fine for attribution, thanks 😊 if not then a comment in the main client class or assemblyinfo would be OK.

The more important thing I'd ask is that you make sure the namespaces, assemblies and embedded id's (like any COM guids in assemblyinfo.cs) are changed so that if anybody needs to use both libs together they don't conflict.

Good luck with your project!

@Yortw
Copy link
Owner

Yortw commented Jan 5, 2018

Thinking about this, but it may be possibly for you just to replace the jsob project. The core spooky Lib might still work, if you just replace the bit that does the request/response formatting. I recently did this to support XML-RPC. Maybe this is what you meant though?

@DNATechAdmin
Copy link
Author

DNATechAdmin commented Jan 7, 2018 via email

@Yortw Yortw closed this as completed Jan 21, 2018
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