public string GetApprovedDataToSyncSecure(List<int> mdaIdList, SystemUser user) { if (mdaIdList.Count == 0) return string.Empty; //TODO check that all these mda's are from the same installation if (LoginRemoteService(user)) { InstallationServices installationServices = new InstallationServices(); int siteId = installationServices.GetSiteIdFromMDAIdOnServer(mdaIdList.First()); string feedback = syncProxy.SendApprovedData(_tokenHeader, siteId); XDocument xDoc = XDocument.Parse(Crypto.DecryptStringAES(feedback, installationServices.InstallationTokenBySiteId(siteId))); if ((bool)xDoc.Element("SecuredWebService").Attribute("success")) { //TODO using .Value throws "Data at the root level is invalid. Line 1, position 1." exception //investigate whether the server is using wrong encoding which can be a pain in the ass in future. //However it seems using .ToString() solves it. //string test = xDoc.Element("SecuredWebService").ToString(); //string test1 = xDoc.Element("SecuredWebService").Value; XDocument xDocData = XDocument.Parse(xDoc.Element("SecuredWebService").Element("data").Element("Approved").ToString()); ImportApprovedData(xDocData); return Crypto.EncryptStringAES(xDocData.ToString(), installationServices.InstallationTokenByMDAId(mdaIdList.First())); } } return string.Empty; }