本文整理汇总了C#中System.IO.StreamReader.ReadAsMany方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.ReadAsMany方法的具体用法?C# StreamReader.ReadAsMany怎么用?C# StreamReader.ReadAsMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了StreamReader.ReadAsMany方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeAsync
public async Task<XDocument> InvokeAsync(string operationName, IDictionary<string, object> args)
{
NatDiscoverer.TraceSource.TraceEvent(TraceEventType.Verbose, 0, "SOAPACTION: **{0}** url:{1}", operationName,
_url);
byte[] messageBody = BuildMessageBody(operationName, args);
HttpWebRequest request = BuildHttpWebRequest(operationName, messageBody);
if (messageBody.Length > 0)
{
using (var stream = await request.GetRequestStreamAsync().ConfigureAwait(false))
{
await stream.WriteAsync(messageBody, 0, messageBody.Length).ConfigureAwait(false);
}
}
using(var response = await GetWebResponse(request).ConfigureAwait(false))
{
var stream = response.GetResponseStream();
var contentLength = response.ContentLength;
var reader = new StreamReader(stream, Encoding.UTF8);
var responseBody = contentLength != -1
? reader.ReadAsMany((int) contentLength)
: reader.ReadToEnd();
var responseXml = GetXmlDocument(responseBody);
response.Dispose();
return responseXml;
}
}
示例2: InvokeAsync
public Task<XmlDocument> InvokeAsync(string operationName, IDictionary<string, object> args)
{
NatDiscoverer.TraceSource.TraceEvent(TraceEventType.Verbose, 0, "SOAPACTION: **{0}** url:{1}", operationName,
_url);
byte[] messageBody = BuildMessageBody(operationName, args);
HttpWebRequest request = BuildHttpWebRequest(operationName, messageBody);
Task<WebResponse> responseTask;
if (messageBody.Length > 0)
{
Stream requestStream = null;
responseTask = Task.Factory.FromAsync<Stream>(request.BeginGetRequestStream, request.EndGetRequestStream, null)
.ContinueWith(requestSteamTask =>
{
requestStream = requestSteamTask.Result;
return Task.Factory.FromAsync<byte[], int, int>(requestStream.BeginWrite,
requestStream.EndWrite, messageBody, 0, messageBody.Length, null);
})
.Unwrap()
.ContinueWith(streamWriteTask =>
{
requestStream.Close();
return GetWebResponse(request);
})
.Unwrap();
}
else
{
responseTask = GetWebResponse(request);
}
return responseTask.ContinueWith(task =>
{
using (WebResponse response = task.Result)
{
var stream = response.GetResponseStream();
var contentLength = response.ContentLength;
var reader = new StreamReader(stream, Encoding.UTF8);
var responseBody = contentLength != -1
? reader.ReadAsMany((int)contentLength)
: reader.ReadToEnd();
var responseXml = GetXmlDocument(responseBody);
response.Close();
return responseXml;
}
});
}