I'm attempting to call CoreServiceSession's ReadSchemaFields and pass the result to Frank's wrapper for content & metadata found here.
However, when I call ReadSchemaFields with the ID of a metadata schema used on a page I get an "Object reference not set to an instance..." error. I've quadruple-checked that the reference error is indeed from within the internal CoreService's call to ReadSchemaFields and I guess I'm wondering if I'm just missing something that states metadata schemas cannot be used with this method, that it's solely intended for components (which Frank's has an example of using it to get a folder's metadata schema fields, so I feel it's possible). With TOM.NET you could create an ItemFields object using either a component's data/schema, page's metadata/schema, keyword's metadata/schema, etc. I was expecting the ReadSchemaFields method to be similarly generic.
My code (simplified) is:
VersionedItemData item = client.Read(CIUtility.GetDynamicUri(CurrentWorkItem.Subject.IdRef)) as VersionedItemData;
if (item != null)
{
log.Debug("Metadata " + item.Metadata);
// Prints: Work Metadata - <Metadata xmlns="uuid:776EC2D6-37AD-4E56-86C2-26D1967D92D9">
// <isSecure>Yes</isSecure>
// <sessionTimeout>20</sessionTimeout>
// </Metadata>
log.Debug("Metadata Schema - " + item.MetadataSchema.IdRef);
// Prints: Metadata Schema - tcm:5-35-8
if (item.MetadataSchema != null && !String.IsNullOrWhiteSpace(item.MetadataSchema.IdRef) && !TcmUri.IsNullOrUriNull(new TcmUri(item.MetadataSchema.IdRef)))
{
log.Debug("Get schema fields");
// Prints
SchemaFieldsData schemaFields = client.ReadSchemaFields(item.MetadataSchema.IdRef, true, new ReadOptions());
// Error occurs
if (schemaFields == null)
log.Debug("No schema fields");
// Doesn't print
log.Debug("Hello world.");
// Doesn't print
...
}
...
}
Am I just stuck with parsing the XML by hand if I'm dealing with Metadata? Or have I missed something terribly obvious (I am working on very little sleep right now)?