Simple OGo<->Mono Tutorial
Walk through of the requirements to connect to OGo from Mono.
1.) Add the file CookComputing.XmlRpc.dll as a reference for your project.
2.) Use the namespace
using CookComputing.XmlRpc;
3.) Declare an object which contains the proxies for the methods you want to use:
namespace whitemice.MOGI {
public interface IOGo {
[XmlRpcMethod("system.getHostName")]
string getHostName();
[XmlRpcMethod("account.getTeamsForLogin")]
Array GetAccountsTeams(string login);
....
/// End of interface IOGo
}
/// End of namespace
}
4.) Instance a XmlRpcClientProtocol object and an instance of your interface class.
namespace whitemice.MOGI {
public class OpenGroupwareServer {
protected IOGo serverProxy;
protected XmlRpcClientProtocol rpcClient;
public OpenGroupwareServer() {
this.serverProxy = (IOGo)XmlRpcProxyGen.Create(typeof(IOGo));
this.rpcClient = (XmlRpcClientProtocol)this.serverProxy;
this.rpcClient.ProtocolVersion = HttpVersion.Version10;
this.rpcClient.PreAuthenticate = true;
/// End of constructor method OpenGroupwareServer
}
/// Accessor for setting up credentials
public virtual NetworkCredential Credentials {
get {
return (NetworkCredential)this.rpcClient.Credentials;
}
set {
this.rpcClient.Credentials = value;
}
/// End of accessor Credentials
}
/// Accessor for setting the URL to the XML-RPC service.
public virtual string Url {
get {
return this.rpcClient.Url;
}
set {
this.rpcClient.Url = value;
}
/// End of accessor Url
}
/// Accessor to set the XML-RPC call timeout
/// Default may be much to short
public virtual int Timeout {
get {
return this.rpcClient.Timeout;
}
set {
if ((value > 1) && (value < 99999))
this.rpcClient.Timeout = value;
}
/// End of accessor Timeout
}
/// Wrapper method to call the method from the interface class
/// This is a good point to add caching, error handing, etc...
public virtual new string GetHostName() {
/*
LogMessage("Server", logSecret, 128, "Call GetHostName", "");
lastAccess = DateTime.Now;
*/
return base.GetHostName();
/// End of wrapper method GetHostName
}
/// End of class OpenGroupwareServer
}
/// End namespace
}
4.1.) It is imperitive that you set the protocol version and preauthenticate flags. If you get an error setting the protocol version then your copy of the CookComputing assembly is not current enough.
5.) Create an instance of your server object and setup basic parameters.
ogoServer = new OpenGroupwareServer();
ogoServer.URL = "http://throw.morrison.iserv.net/RPC2";
ogoServer.Timeout = 18000;
6.) Your app needs to create a credential object
ogoServer.Credentials = new NetworkCredential(entry_login_username.Text, entry_login_password.Text, "");
7. You should be able to make calls now!
Console.WriteLine("OGo Hostname: {0}", ogoServer.GetHostName());
P.S. Use your own namespace.
2.) Use the namespace
using CookComputing.XmlRpc;
3.) Declare an object which contains the proxies for the methods you want to use:
namespace whitemice.MOGI {
public interface IOGo {
[XmlRpcMethod("system.getHostName")]
string getHostName();
[XmlRpcMethod("account.getTeamsForLogin")]
Array GetAccountsTeams(string login);
....
/// End of interface IOGo
}
/// End of namespace
}
4.) Instance a XmlRpcClientProtocol object and an instance of your interface class.
namespace whitemice.MOGI {
public class OpenGroupwareServer {
protected IOGo serverProxy;
protected XmlRpcClientProtocol rpcClient;
public OpenGroupwareServer() {
this.serverProxy = (IOGo)XmlRpcProxyGen.Create(typeof(IOGo));
this.rpcClient = (XmlRpcClientProtocol)this.serverProxy;
this.rpcClient.ProtocolVersion = HttpVersion.Version10;
this.rpcClient.PreAuthenticate = true;
/// End of constructor method OpenGroupwareServer
}
/// Accessor for setting up credentials
public virtual NetworkCredential Credentials {
get {
return (NetworkCredential)this.rpcClient.Credentials;
}
set {
this.rpcClient.Credentials = value;
}
/// End of accessor Credentials
}
/// Accessor for setting the URL to the XML-RPC service.
public virtual string Url {
get {
return this.rpcClient.Url;
}
set {
this.rpcClient.Url = value;
}
/// End of accessor Url
}
/// Accessor to set the XML-RPC call timeout
/// Default may be much to short
public virtual int Timeout {
get {
return this.rpcClient.Timeout;
}
set {
if ((value > 1) && (value < 99999))
this.rpcClient.Timeout = value;
}
/// End of accessor Timeout
}
/// Wrapper method to call the method from the interface class
/// This is a good point to add caching, error handing, etc...
public virtual new string GetHostName() {
/*
LogMessage("Server", logSecret, 128, "Call GetHostName", "");
lastAccess = DateTime.Now;
*/
return base.GetHostName();
/// End of wrapper method GetHostName
}
/// End of class OpenGroupwareServer
}
/// End namespace
}
4.1.) It is imperitive that you set the protocol version and preauthenticate flags. If you get an error setting the protocol version then your copy of the CookComputing assembly is not current enough.
5.) Create an instance of your server object and setup basic parameters.
ogoServer = new OpenGroupwareServer();
ogoServer.URL = "http://throw.morrison.iserv.net/RPC2";
ogoServer.Timeout = 18000;
6.) Your app needs to create a credential object
ogoServer.Credentials = new NetworkCredential(entry_login_username.Text, entry_login_password.Text, "");
7. You should be able to make calls now!
Console.WriteLine("OGo Hostname: {0}", ogoServer.GetHostName());
P.S. Use your own namespace.