.NET API to integrate with Drupal 7 via XML-RPC and Services 3 module
The project I'm introducing here wraps around Charles Cook's excellent XML-RPC.Net library and exposes a number of convenience methods to interact with Drupal 7 installations via Services and related modules.
I have used it in just a small number of personal projects, that's why it is still a "prerelease", but it behaved quite well so I thought it was worth sharing.
Source code is hosted on GitHub, comments and feature requests are very welcome.
Installation
The library is available through NuGet, just remember to check "Show pre-release packages" in your package manager before searching for "drupal", or run the following command in the Package Manager Console
PM> Install-Package Drupal7.Services -Pre

Usage examples (C#)
First of all, you need an instance of the DrupalServices class:
using Drupal7.Services;
using CookComputing.XmlRpc;
drupal7 = new DrupalServices("http://localhost/drupal7/services/xmlrpc");
The class supports authentication, but in my first examples I'll suppose all methods are publicly available to anonymous users.
Services Contact
Install and enable Services Contact, then:
// Retrieve the contact index.
var contacts = drupal7.ContactIndex();
// Send a message to the first contact in list.
bool ok = drupal7.ContactSite("MyName", "mymail@example.com", "TheSubject", int.Parse(contacts[0].cid), "TheMessage", false);
Nodes
Retrieve and “clone” a node
var node = drupal7.NodeRetrieve(1);
var nid = drupal7.NodeCreate(node);
Crete a new node with a term reference field
If you are using an autocomplete term widget (tagging):
var node = new Hashtable
{
{ "type", "news" },
{ "title", "MyNews" },
{ "field_tags", new Hashtable { { "und", "MyTag,MyTag2,MyTag3" } } }
};
var nid = drupal.NodeCreate(node);
More to come…
I'm adding more examples soon, about many common modules, authentication, error handling, asynchronous methods and so on.
Please add a comment to let me know the topic you are most interested in. Thank you!
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion