Skip to content

Commit

Permalink
Merge pull request #435 from shmao/issue217
Browse files Browse the repository at this point in the history
Use new Implemented Async Methods in System.Runtime.Serialization.Xml
  • Loading branch information
shmao authored and roncain committed Oct 26, 2015
1 parent 4bede2a commit 90a6d29
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,7 @@ public override async Task WriteMessageAsync(Message message, Stream stream)
xmlWriter.WriteEndDocument();
}

// The underlying type of xmlWriter, XmlUTF8TextWriter, has not implemented FlushAsync() yet.
xmlWriter.Flush();
await xmlWriter.FlushAsync();
ReturnStreamedWriter(xmlWriter);

if (TD.StreamedMessageWrittenByEncoderIsEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public OperationFormatter(OperationDescription description, bool isRpc, bool isE

protected abstract void AddHeadersToMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest);
protected abstract void SerializeBody(XmlDictionaryWriter writer, MessageVersion version, string action, MessageDescription messageDescription, object returnValue, object[] parameters, bool isRequest);
protected virtual Task SerializeBodyAsync(XmlDictionaryWriter writer, MessageVersion version, string action, MessageDescription messageDescription, object returnValue, object[] parameters, bool isRequest)
{
SerializeBody(writer, version, action, messageDescription, returnValue, parameters, isRequest);
return Task.CompletedTask;
}

protected abstract void GetHeadersFromMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest);
protected abstract object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, string action, MessageDescription messageDescription, object[] parameters, bool isRequest);

Expand Down Expand Up @@ -356,7 +362,7 @@ private async Task SerializeBodyContentsAsync(XmlDictionaryWriter writer, Messag
return;
}

SerializeBody(writer, version, RequestAction, messageDescription, returnValue, parameters, isRequest);
await SerializeBodyAsync(writer, version, RequestAction, messageDescription, returnValue, parameters, isRequest);
}

private IAsyncResult BeginSerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, object[] parameters, object returnValue, bool isRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ private Stream GetStreamAndWriteStartWrapperIfNecessary(XmlDictionaryWriter writ
return streamValue;
}

private Task<Stream> GetStreamAndWriteStartWrapperIfNecessaryAsync(XmlDictionaryWriter writer, object[] parameters, object returnValue)
private async Task<Stream> GetStreamAndWriteStartWrapperIfNecessaryAsync(XmlDictionaryWriter writer, object[] parameters, object returnValue)
{
Stream streamValue = GetStreamValue(parameters, returnValue);
if (streamValue == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(_partName);
if (WrapperName != null)
writer.WriteStartElement(null, WrapperName, WrapperNamespace);
writer.WriteStartElement(null, PartName, PartNamespace);
return Task.FromResult(streamValue);
await writer.WriteStartElementAsync(null, WrapperName, WrapperNamespace);
await writer.WriteStartElementAsync(null, PartName, PartNamespace);
return streamValue;
}

private void WriteEndWrapperIfNecessary(XmlDictionaryWriter writer)
Expand Down

0 comments on commit 90a6d29

Please sign in to comment.