ParseResponse method
Parses the response.
The reader.
Implementation
@override
Future<Object> ParseResponse(EwsServiceXmlReader reader) async {
ServiceResponseCollection<TResponse> serviceResponses =
new ServiceResponseCollection<TResponse>();
await reader.ReadStartElementWithNamespace(
XmlNamespace.Messages, XmlElementNames.ResponseMessages);
for (int i = 0; i < this.GetExpectedResponseMessageCount(); i++) {
// Read ahead to see if we've reached the end of the response messages early.
await reader.Read();
if (reader.IsEndElementWithNamespace(
XmlNamespace.Messages, XmlElementNames.ResponseMessages)) {
break;
}
TResponse response = this.CreateServiceResponse(reader.Service, i);
await response.LoadFromXml(
reader, this.GetResponseMessageXmlElementName());
// Add the response to the list after it has been deserialized because the response
// list updates an overall result as individual responses are added to it.
serviceResponses.Add(response);
}
// If there's a general error in batch processing,
// the server will return a single response message containing the error
// (for example, if the SavedItemFolderId is bogus in a batch CreateItem
// call). In this case, throw a ServiceResponseException. Otherwise this
// is an unexpected server error.
if (serviceResponses.Count < this.GetExpectedResponseMessageCount()) {
if ((serviceResponses.Count == 1) &&
(serviceResponses[0].Result == ServiceResult.Error)) {
throw new ServiceResponseException(serviceResponses[0]);
} else {
throw new ServiceXmlDeserializationException("""string.Format(
Strings.TooFewServiceReponsesReturned,
this.GetResponseMessageXmlElementName(),
this.GetExpectedResponseMessageCount(),
serviceResponses.Count)""");
}
}
await reader.ReadEndElementIfNecessary(
XmlNamespace.Messages, XmlElementNames.ResponseMessages);
return serviceResponses;
}