xmlrpcwsc-dotnet/README.md

258 lines
96 KiB
Markdown
Raw Normal View History

xmlrpcwsc-dotnet
================
Description
-----------
2016-03-14 00:28:10 +01:00
XmlRpc Web Service Client .NET is a C# implementation of XML-RPC, a popular
protocol that uses XML over HTTP to implement remote procedure calls.
2016-03-13 17:20:23 +01:00
This implementation can be used in .NET 4.5, NET 3.5 CF.
2016-03-14 00:28:10 +01:00
This software was tested with Odoo ERP 8 and 9.
2016-03-13 18:00:30 +01:00
Examples are available in the sandbox folder.
Features
--------
- License: LGPL 3
- Language: C#, .NET 4.5
- IDE: Visual Studio 2012, MonoDevelop 5.9.6
2016-03-07 00:26:47 +01:00
- Version: v1.3.0
2016-03-13 17:20:23 +01:00
Links
-----
- http://xmlrpc.scripting.com/
- https://en.wikipedia.org/wiki/XML-RPC
2016-03-13 17:20:23 +01:00
Example Create Partner and Image
--------------------------------
- Source:
2016-03-13 18:00:30 +01:00
```cs
using System;
using XmlRpc;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace sandbox {
class MainClass {
public static string Url = "http://localhost:8069/xmlrpc/2", db = "odoo9", pass = "admin", user = "admin";
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) {
TestCreateRecord();
Console.ReadKey();
}
}
}
2016-03-13 17:20:23 +01:00
```
- Output:
2016-03-13 18:00:30 +01:00
```xml
authenticate
REQUEST:
<?xml version="1.0" encoding="utf-8"?>
<methodCall>
<methodName>authenticate</methodName>
<params>
<param>
<value>
<string>odoo9</string>
</value>
</param>
<param>
<value>
<string>admin</string>
</value>
</param>
<param>
<value>
<string>admin</string>
</value>
</param>
<param>
<value>
<struct />
</value>
</param>
</params>
</methodCall>
2016-03-13 17:20:23 +01:00
2016-03-13 18:00:30 +01:00
RESPONSE:
<?xml version="1.0" encoding="utf-8"?>
<methodResponse>
<params>
<param>
<value>
<int>1</int>
</value>
</param>
</params>
</methodResponse>
LOGIN:
1
create
REQUEST:
<?xml version="1.0" encoding="utf-8"?>
<methodCall>
<methodName>execute_kw</methodName>
<params>
<param>
<value>
<string>odoo9</string>
</value>
</param>
<param>
<value>
<int>1</int>
</value>
</param>
<param>
<value>
<string>admin</string>
</value>
</param>
<param>
<value>
<string>res.partner</string>
</value>
</param>
<param>
<value>
<string>create</string>
</value>
</param>
<param>
<value>
<array>
<data>
<value>
<struct>
<member>
<name>name</name>
<value>
<string>Alb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+v+frQB3ltfoE/sr7R/p9nZj7ZbX/8An2B5/PvWfqWq2FnD51z/AK7H+kW/+fT+R75rh/tnnJ59tqH2iw+x/wCj3Gs9On4/kB0781HNDD/pHnXP2hLn/lzz6/8A1+/9aAOk03Vbmzm1CwvLf5/tn2q3/wCYl/xLdS/H+Z6dKufbLCaa41VP9Imt7z/iVfYP+YVz2Hb8Kx5r9PsHkw3H77/iVX9xZ/8AMSxj+x/U/n09sGtBLM/Zrea5t7u4zef6R/zDf7V/z+XTOaAKf2u/2fY9NuLO3+0f8vF//wASz/kG/wDE4/8A18DqB7V19rfRTwr9oUm6hzBdr9kN95VzH/rIvtP/AC025HPvXAXk3nar9jg+x273H+n3FvYY5/8A146/XFV1tbWdI/O1iFFhRYLe1sf7Y+zWFtH/AKqxTOP9Rlv++hQBT0p79ZtY8640e4PFrb2//IN/tXTf+g2OeO+eKsahePf23mX9uNQ/tT/T5Le1/wCXH6fz9jXJ3nk3lzceTcfaPs959vuCM9/pj8f5YqTR9Ts7WwjmsP7Nufs95/xK9L1n/qJH/id//WoArzTW1zeY+z+XNb2Wby3v8/2bpWf58Y/pzXP2f2b7Hbz2eoDS5tP/AOPm3xnHX6/1/rVy51K5tv7Qm/s/7Rcz/wDPoP7N59T/APq4/AVz7wzT3nnTW95bw/qf7S/4k/6e340AbF5NcvNceTZ/Y/8AQv7P+x/2r/aWm/8AQY/z/jXFyXNzDJbwp+Oqf09+3f8ADGa1IWhs0s4Ybj9xx/pP/MT7fj/h+VY95c6rNNb2v/Hw9v8A6BcAcf8AYE9PTj69qAJJpprBxc/aP+PP/jyPf1/l27/QVbmhfzbaCa4vP9I/1dx/zDc/5/z3HIJrn2N7fYP9J63F6f8AP/1u/NdJZ6k
</value>
</member>
<member>
<name>email</name>
<value>
<string>albert.einstein@email.com</string>
</value>
</member>
</struct>
</value>
</data>
</array>
</value>
</param>
</params>
</methodCall>
RESPONSE:
<?xml version="1.0" encoding="utf-8"?>
<methodResponse>
<params>
<param>
<value>
<int>43</int>
</value>
</param>
</params>
</methodResponse>
READ:
43
```
2016-03-13 17:20:23 +01:00
- Odoo Output:
![](/documents/printscreen-1.png)
![](/documents/printscreen-2.png)
- WinCE PrintScreen Example:
![](/documents/printscreen-3.png)