At A Glance Main Projects Tutorials Resume

Contact


Email: palen1c at gmail.com




Drupal 7 Services 3 REST Server C Sharp Example

Fri, 4 May 2012 10:13:40 EST

An image of the the drupal services 3 tool.
I have been doing a lot of work lateley in the Windows Presentation Foundation(wpf) in my favorite .NET language, c#. As with many projects, I like to incorporate the Drupal content management system. With Services 3 you have to throw your knowledge of previous Drupal Services out the window. There is no service browser and several paradigms have changed. After examining REST vs the XMLRPC server I decided to focus on REST because it is just like POSTing and GETing data to/from web forms, in combination with specific url schemes. I've created a demo application that will allow people to test out the REST server....at the time of writing anyway. Here are a couple of points about services 3.

Login

In Services 3 logged in state is determined by a cookie that the login method returns if valid credentials are provided. There is no system.connect needed. People used to legacy Drupal Services will probably find this really annoying...I kind of did. However it conforms to the same behavior as other popular API's like Facebook and Twitter. This is a POST request.

In this example, by default there is no cookie management when using the HttpWebRequest so we utilize a CookieContainer.

Logout

Logout is also handled by a POST. You can call it as many times as you want, but it will only return a valid result if you currently have a valid cookie.

The example was created using using Visual C# 2010 Express and compiled for an x86 target. Take a close look at the source code and you may happen to stumble uppon several other examples. If you have any questions, please use the comments and I'll be happy to help.

Example Download

Download the Executable Sample

Download the C# Project

Charles Palen has been involved in the technology sector for several years. His formal education focused on Enterprise Database Administration. He currently works as the principal software architect and manager at Transcending Digital where he can be hired for your next contract project. Charles is a full stack developer who has been on the front lines of small business and enterprise for over 10 years. Charles current expertise covers the areas of .NET, Java, PHP, Node.js, Javascript, HTML, and CSS. Charles created Technogumbo in 2008 as a way to share lessons learned while making original products.

Comments

Hua Chen
Hua Chen
May 6, 2014 10:40 am

Many thanks. the program works very well. How can I update nodes by modifying your code?

Joe Hua
Joe Hua
April 11, 2013 08:21 am

Thank you very much! You're my Savior, Mr. Charles Palen. Impressive!

Charles
Charles
January 4, 2013 10:50 am

Hi altair,

The first thing I would check is the massive drupal permissions settings. Are you sure your logged in user has permissions to submit files in the form your trying to to begin with? You can usually navigate to an add/edit form and if the field is not visible you'll know its a drupal permission error.

If that doesn't do the trick I'm sorry as I haven't ever ran the code in .net 3.5 because it was specifically for use in a Kinect application.

altair
altair
January 4, 2013 05:49 am

Hi! I translate your project to vs2008 .net 3.5 windows forms, after login all look like good, but when I try to send image, drupal tell me that access denied for anonymous. I know something with cookies, but code one to one. Maybe problem with .net 3.5. If you know something about this problem please write reply. Thanks

Charles
Charles
May 8, 2012 5:54 pm

Thanks netlooker. I hope you were able to find the demo app helpful. You can use firebug to figure out the correct custom datatype form fields a lot easier than using devel.

netlooker
netlooker
May 8, 2012 5:22 pm

Great job. Do that without documentation is impressive.

Comments are currently disabled.