Has anyone had luck with using a .NET web service to access Sitecore items? I have a number of web applications on my server that are still in Coldfusion. I'd like to be able to call a web service to pull down items, but when I tried to do this I got an exception "Sitecore.Data.Items.Item cannot be serialized because it does not have a parameterless constructor."
Take a look at Sitecore standard web service, you can find it under /sitecore/shell/WebService folder of your solution. It offers some basic operations with Sitecore items and fields, but it is often enough for pulling or saving data.
Hope this helps.
If the Sitecore standard web service doesn't give you what you need, why not write a custom HttpHandler or MCF service or, simplest yet, a Sitecore layout to output your Items in a format that can be consumed by ColdFusion? Is there a reason you need to directly serialize the Item?
I answered this on the SDN forum as well. You can create your own wrapper object which is filled with a Sitecore item and sets its members. The hard part will be creting your members and assigning them from the real Sitecore item. If you want everything then I think it will be difficult. If you just want some stuff then its doable. E.g.
[Serializable]
public class SitecoreItem {
public string ID;
// more members
SitecoreItem(Sitecore.Data.Items.Item scItem) {
this.ID = scItem.ID;
// assign more members from the true Sitecore item
}
}
Then in your WS method fill a new instance with your actual Sitecore item and return it:
return new SitecoreItem(actualSCItem);
If both the serialiser and the deserialiser have access to the Sitecore database, then you can very easily create a wrapper that just serialises the ID, database name, version and language. Then upon deserialisation on the other end, you can re-fetch the same Sitecore item from the database using that information.
If the deserialiser doesn't have access to the database at all, then it really depends on what your needs are for using the data. I typically loop over all the fields (remember to use item.Fields.ReadAll()
first), and store them in a dictionary for easy access. For serialisation, I convert that into a List<T>
of key value pairs and ignore the Dictionary
member (since it can't be serialised) and then re-populate it on deserialisation. I keep a few other properties like ID, Language, Version, Template, Path, etc. on the class too.
Alternatively, if you create a whole model class library so that each template is mapped to a class (some people do), you can (probably) serialise those straight off since they're (probably) no longer bound to a Sitecore item.