From 9f4b6264d6971a015a28361c9d70297170b5f199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Pi=C3=B1a?= Date: Sun, 13 Mar 2016 11:20:23 -0500 Subject: [PATCH] Update readme --- .gitignore | 1 + README.md | 32 ++++++++- sandbox/Program.cs | 170 ++++++++++++++++++++++----------------------- 3 files changed, 114 insertions(+), 89 deletions(-) diff --git a/.gitignore b/.gitignore index 31e71ac..a82bd3d 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ $RECYCLE.BIN/ *.msi *.msm *.msp +*.mdb # Windows shortcuts *.lnk diff --git a/README.md b/README.md index 25a4de1..1491561 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,10 @@ xmlrpcwsc-dotnet Description ----------- -XmlRpc Web Service Client is a C# implementation of XML-RPC, a popular +XmlRpc Web Service Client is a C# implementation of XML-RPC, a popular protocol that uses XML over HTTP to implement remote procedure calls. +This implementation can be used in .NET 4.5, NET 3.5 CF. +This software was tested with Odoo 8 and 9. Features @@ -17,7 +19,31 @@ Features - Version: v1.3.0 -Documentation -------------- +Links +----- - http://xmlrpc.scripting.com/ - https://en.wikipedia.org/wiki/XML-RPC + + +Example Create Partner and Image +-------------------------------- +- Source: + +```c# +``` + +- Output: + +``` +``` + + +- Odoo Output: + +![](/documents/printscreen-1.png) + +![](/documents/printscreen-2.png) + +- WinCE PrintScreen Example: + +![](/documents/printscreen-3.png) diff --git a/sandbox/Program.cs b/sandbox/Program.cs index c458719..312852f 100644 --- a/sandbox/Program.cs +++ b/sandbox/Program.cs @@ -31,7 +31,7 @@ namespace sandbox { /// class MainClass { - public static string Url = "http://localhost:8069/xmlrpc/2", db = "odoo", pass = "admin", user = "admin"; + public static string Url = "http://localhost:8069/xmlrpc/2", db = "odoo9", pass = "admin", user = "admin"; public static void TestRequestXml() { XmlRpcRequest request = new XmlRpcRequest("version"); @@ -160,7 +160,7 @@ namespace sandbox { XmlRpcRequest requestRead = new XmlRpcRequest("execute_kw"); requestRead.AddParams(db, responseLogin.GetInt(), pass, "res.partner", "read", - XmlRpcParameter.AsArray( + XmlRpcParameter.AsArray( responseSearch.GetArray() ) ); @@ -209,75 +209,7 @@ namespace sandbox { Console.WriteLine(); Console.WriteLine(response.GetString()); } - } - - public static void TestCreateRecord() { - XmlRpcClient client = new XmlRpcClient(); - client.Url = Url; - client.Path = "common"; - - // LOGIN - - XmlRpcRequest requestLogin = new XmlRpcRequest("authenticate"); - requestLogin.AddParams(db, user, pass, XmlRpcParameter.EmptyStruct()); - - XmlRpcResponse responseLogin = client.Execute(requestLogin); - - // Console.WriteLine("authenticate"); - // Console.WriteLine("REQUEST: "); - // client.WriteRequest(Console.Out); - - // Console.WriteLine(); - // Console.WriteLine(); - // Console.WriteLine("RESPONSE: "); - // client.WriteResponse(Console.Out); - - Console.WriteLine(); - Console.WriteLine(); - Console.WriteLine("LOGIN: "); - if (responseLogin.IsFault()) { - Console.WriteLine(responseLogin.GetFaultString()); - } else { - Console.WriteLine(responseLogin.GetString()); - } - - // CREATE - - client.Path = "object"; - - XmlRpcRequest requestCreate = new XmlRpcRequest("execute_kw"); - requestCreate.AddParams(db, responseLogin.GetInt(), pass, "res.partner", "create", - XmlRpcParameter.AsArray( - XmlRpcParameter.AsStruct( - XmlRpcParameter.AsMember("name", "Albert Einstein") - , XmlRpcParameter.AsMember("image", Convert.ToBase64String(File.ReadAllBytes("img/einstein.jpg"))) - , XmlRpcParameter.AsMember("email", "albert.einstein@email.com") - ) - ) - ); - - XmlRpcResponse responseCreate = client.Execute(requestCreate); - - // Console.WriteLine(); - // Console.WriteLine(); - // Console.WriteLine("create"); - // Console.WriteLine("REQUEST: "); - // client.WriteRequest(Console.Out); - - // Console.WriteLine(); - // Console.WriteLine(); - // Console.WriteLine("RESPONSE: "); - // client.WriteResponse(Console.Out); - - Console.WriteLine(); - Console.WriteLine(); - Console.WriteLine("READ: "); - if (responseCreate.IsFault()) { - Console.WriteLine(responseCreate.GetFaultString()); - } else { - Console.WriteLine(responseCreate.GetString()); - } - } + } public static void TestSearchReadRecords() { XmlRpcClient client = new XmlRpcClient(); @@ -322,25 +254,23 @@ namespace sandbox { ) ), XmlRpcParameter.AsStruct( - XmlRpcParameter.AsMember("fields", XmlRpcParameter.AsArray("name","email")) + XmlRpcParameter.AsMember("fields", XmlRpcParameter.AsArray("name", "email")) // ,XmlRpcParameter.AsMember("limit", 2) ) - ); - - + ); XmlRpcResponse responseSearch = client.Execute(requestSearch); - // Console.WriteLine(); - // Console.WriteLine(); - // Console.WriteLine("search"); - // Console.WriteLine("REQUEST: "); - // client.WriteRequest(Console.Out); + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("search"); + Console.WriteLine("REQUEST: "); + client.WriteRequest(Console.Out); - // Console.WriteLine(); - // Console.WriteLine(); - // Console.WriteLine("RESPONSE: "); - // client.WriteResponse(Console.Out); + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("RESPONSE: "); + Console.WriteLine(); Console.WriteLine(); @@ -353,12 +283,80 @@ namespace sandbox { } + public static void TestCreateRecord() { + XmlRpcClient client = new XmlRpcClient(); + client.Url = Url; + client.Path = "common"; + + // LOGIN + + XmlRpcRequest requestLogin = new XmlRpcRequest("authenticate"); + requestLogin.AddParams(db, user, pass, XmlRpcParameter.EmptyStruct()); + + XmlRpcResponse responseLogin = client.Execute(requestLogin); + + Console.WriteLine("authenticate"); + Console.WriteLine("REQUEST: "); + client.WriteRequest(Console.Out); + + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("RESPONSE: "); + client.WriteResponse(Console.Out); + + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("LOGIN: "); + if (responseLogin.IsFault()) { + Console.WriteLine(responseLogin.GetFaultString()); + } else { + Console.WriteLine(responseLogin.GetString()); + } + + // CREATE + + client.Path = "object"; + + XmlRpcRequest requestCreate = new XmlRpcRequest("execute_kw"); + requestCreate.AddParams(db, responseLogin.GetInt(), pass, "res.partner", "create", + XmlRpcParameter.AsArray( + XmlRpcParameter.AsStruct( + XmlRpcParameter.AsMember("name", "Albert Einstein") + , XmlRpcParameter.AsMember("image", Convert.ToBase64String(File.ReadAllBytes("img/einstein.jpg"))) + , XmlRpcParameter.AsMember("email", "albert.einstein@email.com") + ) + ) + ); + + XmlRpcResponse responseCreate = client.Execute(requestCreate); + + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("create"); + Console.WriteLine("REQUEST: "); + client.WriteRequest(Console.Out); + + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("RESPONSE: "); + client.WriteResponse(Console.Out); + + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("READ: "); + if (responseCreate.IsFault()) { + Console.WriteLine(responseCreate.GetFaultString()); + } else { + Console.WriteLine(responseCreate.GetString()); + } + } + public static void Main(string[] args) { - TestRequestXml(); + // TestRequestXml(); // TestResponseXml(); // TestReadVersion(); // TestReadRecords(); - // TestCreateRecord(); + TestCreateRecord(); // TestSearchReadRecords(); Console.ReadKey(); }