Exemplo n.º 1
0
        public static void TestReadVersion()
        {
            XmlRpcClient client = new XmlRpcClient();

            client.Url  = Url;
            client.Path = "common";

            XmlRpcResponse response = client.Execute("version");

            Console.WriteLine("version");
            Console.WriteLine("REQUEST: ");
            client.WriteRequest(Console.Out);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("RESPONSE: ");
            client.WriteResponse(Console.Out);

            Console.WriteLine();
            Console.WriteLine();
            if (response.IsFault())
            {
                Console.WriteLine(response.GetFaultString());
            }
            else
            {
                Console.WriteLine(response.GetString());
            }
        }
Exemplo n.º 2
0
        public string getResponse(string actionName, KeyValuePair <String, object>[] arrParams)
        {
            XmlRpcRequest request = new XmlRpcRequest(this.className + "." + actionName);

            request.AddParamStruct(arrParams);
            XmlRpcResponse response = this.clientXmlRpc.Execute(request);

            return(parseResponse(response.GetString()));
        }
Exemplo n.º 3
0
        public static void TestResponseXml()
        {
            XmlDocument testDoc = new XmlDocument();

            // testDoc.AppendChild(testDoc.CreateElement("methodResponse"));
            // testDoc.LoadXml("<methodResponse><fault><value><struct><member><name>faultCode</name><value><int>1</int></value></member><member><name>faultString</name><value><string>Error</string></value></member></struct></value></fault></methodResponse>");
            testDoc.LoadXml("<methodResponse><params><param><value><array><data><value><int>7</int></value><value><int>11</int></value><value><int>8</int></value><value><int>44</int></value><value><int>10</int></value><value><int>12</int></value></data></array></value></param></params></methodResponse>");

            testDoc.Save(Console.Out);
            XmlRpcResponse response = ResponseFactory.BuildResponse(testDoc);

            if (response.IsFault())
            {
                Console.WriteLine(response.GetFaultString());
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine(response.GetString());
            }
        }
Exemplo n.º 4
0
        public static void TestReadRecords()
        {
            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: "******"object";

            XmlRpcRequest requestSearch = new XmlRpcRequest("execute_kw");

            requestSearch.AddParams(db, responseLogin.GetInt(), pass, "res.partner", "search",
                                    XmlRpcParameter.AsArray(
                                        XmlRpcParameter.AsArray(
                                            XmlRpcParameter.AsArray("is_company", "=", true), XmlRpcParameter.AsArray("customer", "=", true)
                                            )
                                        )
                                    );

            requestSearch.AddParamStruct(
                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("RESPONSE: ");
            // client.WriteResponse(Console.Out);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("SEARCH: ");
            if (responseSearch.IsFault())
            {
                Console.WriteLine(responseSearch.GetFaultString());
            }
            else
            {
                Console.WriteLine(responseSearch.GetString());
            }

            // READ

            XmlRpcRequest requestRead = new XmlRpcRequest("execute_kw");

            requestRead.AddParams(db, responseLogin.GetInt(), pass, "res.partner", "read",
                                  XmlRpcParameter.AsArray(
                                      responseSearch.GetArray()
                                      )
                                  );

            requestRead.AddParamStruct(XmlRpcParameter.AsMember("fields",
                                                                XmlRpcParameter.AsArray("name")
                                                                )
                                       );

            XmlRpcResponse responseRead = client.Execute(requestRead);

            // Console.WriteLine();
            // Console.WriteLine();
            // Console.WriteLine("read");
            // 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 (responseRead.IsFault())
            {
                Console.WriteLine(responseRead.GetFaultString());
            }
            else
            {
                Console.WriteLine(responseRead.GetString());
            }
        }
Exemplo n.º 5
0
        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: "******"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", "*****@*****.**")
                                            )
                                        )
                                    );

            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());
            }
        }