Enjoy
John
I also worked on a prototype last Friday that works across all framework
versions. I've attached it for your use/review. A client-side proxy can
also be implemented on top of this by inheriting and adding service
methods that internally delegate to base's Invoke. Only synchronous
calls are supported for now.
Cheers,
Atif
very clever.
I'm trying to use C# with Jayrock in the client side and Json-rpc with
php in the server side, I just tried to run your example, of course I
change the url and the method, but always I have:
{"response":"\"The method you requested, , was not
found.\"","error":"1","id":null}
I tested the web services and this is working good.
- Atif
System.Net.Sockets.Socket s = ConnectSocket("localhost", 80);
// my method
string txt = "{\"method\": \"mymethod\" ,\"params\":
{\"user\":\"me\",\"password\":\"pass\"},\"id\":8}";
System.Text.StringBuilder sb = new
System.Text.StringBuilder();
sb.Append("POST /myapp/server.php HTTP/1.0\r\n");
sb.Append("Host: localhost\r\n}");
sb.Append("User-Agent: myJsonApp\r\n");
sb.Append("Connection: close\r\n");
sb.Append("Content-Type: application/json\r\n");
sb.Append("Content-Length: " + txt.Length.ToString() +
"\r\n");
sb.Append("Accept: application/json\r\n");
sb.Append("\r\n");
sb.Append(txt);
byte[] send =
System.Text.Encoding.UTF8.GetBytes(sb.ToString());
s.Send(send);
This works, but, How I can do the same in JsonRpcClient.Invoke, I don't
know how to set the content-length.
JsonObject call = new JsonObject();
call["id"] = ++_id;
call["method"] = method;
call["params"] = args;
string callString = JsonConvert.ExportToString(call);
byte[] callBytes = Encoding.UTF8.GetBytes(callString);
WebRequest request = GetWebRequest(new Uri(Url));
request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";
request.ContentLength = callBytes.Length;
using (Stream stream = request.GetRequestStream())
stream.Write(callBytes, 0, callBytes.Length);
I haven't compiled this so it may contain an error or two, but you get the general idea.