November Happy Hour will be moved to Thursday December 5th.

InvalidCastException saving page via DataFactoryService webservice

Vote:
 

I am using a webservice that exposes the EPiServer.WebServices.DataFactoryService to automate the creation of sites.

This has successfully copied a page but I now need to change some properties on the newly created page.

I called GetPage() to get the raw page, changed a property and set IsModified to true and finally Save(rawPage, SaveAction.Save) to save it back. Unfortunately the Save method results in:


soap:ServerSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidCastException: Unable to cast object of type 'EPiServer.Core.PropertyString' to type 'EPiServer.SpecializedProperties.PropertyUrl'.
at EPiServer.DataAccess.PageSaveDB.SetupPageLinkUrl()
at EPiServer.DataAccess.PageSaveDB.SavePageVersionData(String currentUser)
at EPiServer.DataAccess.PageSaveDB.CreateAndSave(SaveAction action, String currentUser)
at EPiServer.DataAccess.PageSaveDB.Save(PageData page, SaveAction action, String currentUser)
at EPiServer.LocalPageStore.Save(PageData page, SaveAction action, AccessLevel access)
at EPiServer.DataFactory.Save(PageData page, SaveAction action, AccessLevel access)
at EPiServer.DataFactory.Save(PageData page, SaveAction action)
at EPiServer.WebServices.DataFactoryService.Save(RawPage page, SaveAction action)
--- End of inner exception stack trace ---

This appears to be down to an internal call to:

   ServiceHelper.RemoveTrustedData(page);

The above method strips out all the TypeName and AssemblyName values which means the PageLinkProperty which did have a TypeName of PropertyUrl is removed.  I guess it later defaults to PropertyString. Internally this then tries to call SetupPageLinkUrl which expects the PageLinkUrl property to be a PropertyUrl but due to RemoveTrustedData, this is now a PropertyString.

How can I change page properties in an automated way? Am I doing something wrong? (Note I have also tried using PageStoreFactory and get the same issue). We are using 5.1 SP3.

#27214
Jan 21, 2009 10:28
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.