i was trying to create a console application so i could take an export package using the API(http://erichuiza.blogspot.nl/2013/12/tridion-2013-sp1-api-improvements.html) I have this code:
ImportExportServiceClient client = new ImportExportServiceClient();
ReadFromTxt txtObject= new ReadFromTxt();
Selection[] selection = txtObject.fetchList();
ExportInstruction instruction = new ExportInstruction { LogLevel = LogLevel.Normal };
string processId = client.StartExport(selection, instruction);
This gives me the error
Unhandled Exception: System.ServiceModel.CommunicationException: There was an er ror while trying to serialize parameter http://www.sdltridion.com/ContentManager /ImportExport/2013:selections. The InnerException message was 'Type 'ExportImpor tBusiness.implementSelection' with data contract name 'implementSelection:http:/ /schemas.datacontract.org/2004/07/ExportImportBusiness' is not expected. Conside r using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by a dding them to the list of known types passed to DataContractSerializer.'
This breaks at client.StartExport.
ExportImportBusiness is the namespace of my business class.
The method ReadFromTxt() returns an array of Selection. It reads from a text file containing TCM-ids, 1 in a row.
Code from ReadFromTxt
public class ReadFromTxt
{
public Tridion.ContentManager.ImportExport.Selection[] fetchList()
{
Tridion.ContentManager.ImportExport.Selection[] a = null; ;
a = populateArray(a);
Console.WriteLine("After populating Array");
Console.WriteLine(a[0].ToString());
return a;
}
public Tridion.ContentManager.ImportExport.Selection[] populateArray(Tridion.ContentManager.ImportExport.Selection[] a)
{
Console.WriteLine("Inside method populateArray. About to populate Array");
string filePath = System.Configuration.ConfigurationManager.AppSettings["FilePath"];
Console.WriteLine("Value of variable file is" +filePath);
int count = File.ReadLines(filePath).Count();
a = InitializeArray<implementSelection>(count, filePath);
return a;
}
public implementSelection[] InitializeArray<T>(int length, string filePath) where T : new()
{
Console.WriteLine("Inside method InitializeArray ");
implementSelection[] array = new implementSelection[length];
for (int i = 0; i < length; ++i)
{
string line = File.ReadLines(filePath).Skip(i - 1).Take(1).First();
//T item = new T();
implementSelection item = new implementSelection(line);
// item.field = line;
array[i] = item;
Console.WriteLine(array[i]);
}
Console.WriteLine(array.GetType());
return array;
}
public ProcessState WaitForProcessFinish(ImportExportServiceClient client, string processId)
{
do
{
Thread.Sleep(1000);
ProcessState? processState = client.GetProcessState(processId);
if (processState == ProcessState.Finished || processState == ProcessState.Aborted || processState == ProcessState.AbortedByUser)
{
return processState.Value;
}
}
while (true);
}
public void DownloadPackage(string processId, string packageLocation)
{
var downloadClient = new ImportExportStreamDownloadClient();
// downloadClient.DownloadProcessLogFile(processId, true) to download log file
using (var packageStream = downloadClient.DownloadPackage(processId, deleteFromServerAfterDownload: true))
{
using (var fileStream = File.Create(packageLocation))
{
packageStream.CopyTo(fileStream);
}
}
}
}
And i have used the Selection class as below:
public class implementSelection : Selection
{
public implementSelection()
{ }
public implementSelection(string value)
{
field = value;
}
public string field = "abdc";
public override string ToString()
{
return field;
}
}
Thanks in advance