.net Starter

Extending the system, interesting uses and API twiddling.
Post Reply
phil4
Posts: 34
Joined: Fri Nov 25, 2011 11:27 pm
Location: Oxfordshire
Contact:

.net Starter

Post by phil4 » Tue Dec 06, 2011 7:52 pm

As there are no examples for .net coding, I thought I'd share what I learned about using the API in .net.

Please take the following as purely a hint if you've no idea where to start. I doubt it's perfect, there's one or two drawbacks I've not solved, but I hope it at least gets someone started.

So:

The API uses XML-RPC, not SOAP and so can't be added as a "web reference". Nor used in the normal WebMethod way.

To make things easier I used an XML-RPC provider from: http://www.xml-rpc.net/ It provides a library which allows you to make the equiv of WebMethod calls.

The following is a snippet of code using the above that allows login and logout (no tabs I'm afraid):

Code: Select all

using CookComputing.XmlRpc;


namespace AlertMeAPI
{
      public class AlertMe_API
{

private string sessionToken = "";

private IXAMApi proxy = XmlRpcProxyGen.Create<IXAMApi>();

public bool doLogin(string strUsername, string strPassword)
{ 
      sessionToken = proxy.login(strUsername, strPassword, "APITest");

      return true;
}

public bool doLogout()
{
      string strReturn="";
      if (sessionToken != "")
      {
            strReturn = proxy.logout(sessionToken);
      }
      return true;
}
}

[XmlRpcUrl("https://api.alertme.com/webapi/v2")]
public interface IXLogon : IXmlRpcProxy
{
      [XmlRpcMethod]
      string login(string username,string password, string callerDescription);

      [XmlRpcMethod]
      string logout(string sessionToken);
}
}
The later section is an Interface, which declares the XmlRpcMethods (and their associated arguments). We can then consume that in the first part of the code in normal .net methods, passing and receiving strings, ints etc. All of the calls you'll note are through the proxy declared at the top.

I've started writing a wrapper based on the above, but trimmed it all down to provide the above which I hope is a little clearer.

I would hope that many have realised the above and got on just fine without reading this, but thought that it may be helpful to some.

User avatar
roobarb!
Site Admin
Posts: 225
Joined: Mon Nov 21, 2011 4:56 pm
Location: Manchester, UK
Contact:

Re: .net Starter

Post by roobarb! » Wed Dec 07, 2011 12:24 pm

That's handy stuff. I'm not a .net person myself, but it's nice to have a peek at the way this is done. :)
Alerty - you could control your AlertMe system with my third-party app for iPhone and iPod Touch. Used to be available on iTunes!

Post Reply