
Good day guys,
i have written the code below in x++ to simply consume the Query service in addition to Metadata service inside another instance of AX.
As you know, consuming the Query service to execute static AOT query is just the easiest thing you might ever do while integrating AX, it gets a bit complected when you want to set query range (filters) and involve the metadata service though.
Anyways, i 've got everything fine and working. But with an exception that is telling "There are multiple root elements. Line 1, position 2".
here is my code part that fires the exception (specifically on the last line when calling ReadObject(memoryStream)) :
_metaDataClient = AifUtil::createServiceClient(CLRInterop::getType("NepMetaDataService.AxMetadataServiceClient")); metaSer = new System.Runtime.Serialization.DataContractSerializer(_queryMeta.GetType()); querySer = new System.Runtime.Serialization.DataContractSerializer(_query.GetType()); _querysMeta = _metaDataClient.GetQueryMetadataByName(queryNames); _queryMeta = _querysMeta.get_Item(0); metaSer.WriteObject(memoryStream, _queryMeta); memoryStream.Seek(0, System.IO.SeekOrigin::Begin); _query = querySer.ReadObject(memoryStream); //exception fired.
moreover, i tried to use the XmlReader and XmlWriter as shown here and got null _query object and therefore no results,
settings.set_ConformanceLevel(System.Xml.ConformanceLevel::Fragment);
xmlReader = System.Xml.XmlReader::Create(memoryStream, settings);
xmlWriter = System.Xml.XmlWriter::Create(memoryStream);
_querysMeta = _metaDataClient.GetQueryMetadataByName(queryNames);
_queryMeta = _querysMeta.get_Item(0);
metaSer.WriteObject(xmlWriter, _queryMeta);
memoryStream.Seek(0, System.IO.SeekOrigin::Begin);
xmlReader = System.Xml.XmlReader::Create( (memoryStream, settings);
_query = querySer.ReadObject(xmlReader);
Although my code shown up in green gives the required result, i am tired to get rid of that exception. any help please?
*This post is locked for comments
I have the same question (0)