PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Sitecore Web Service Pitfalls

Note: This article was originally published at Planet PHP on 29 May 2012.
Planet PHP

I recently started an adventure involving Sitecore's out-of-the-box web service. In fact, I didn't know such a thing existed in Sitecore until I searched the web for information about accessing Sitecore from a process outside the ASP.NET runtime.

The good news is a web service exists. The bad news is the documentation barely exists. Apart from a documen titled The Sitecore Web Service Reference Guide on the Sitecore Developer Network, you literally are on your own.

Thankfully, there's no problem in getting it to work. The problem is actually using the web service.

Problem 1: Return values

The document describes - in nothing more than just a few words - all available methods. The return value is always of the type System.Xml.Linq.XElement but no part of the documentation shows what the return value actually looks like. After some debugging I found out the result always takes this form:

ok|failed ...

Problem 2: The documentation is wrong

Ouch! The documentation for the Save method tells us that it needs the XML representation of an item. A special note even points us in the right wrong direction:

You can obtain the XML representation by the GetXML method.

So you call GetXML, modify the XML to include your updates and then supply that XML to the Save method. Been there, done that and received the status ok reply. Woohoo!

a or not. Despite the ok from Sitecore I didn't see my updated field value. Time to figure out what the Save method actually does using dotPeek. Upon inspection it seems the method expects an XML like:

That XML is completely different than the XML representation of an item! I changed my methods to produce the aonewa XML format anda it worked

I really hope I don't need to create a follow up post!