Пример #1
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()));
        }
Пример #2
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());
            }
        }