当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.ReadAsMany方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:haroldma,项目名称:Universal.Nat,代码行数:32,代码来源:SoapClient.cs

示例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;
                }
            });
        }
开发者ID:mcatanzariti,项目名称:Open.NAT,代码行数:51,代码来源:SoapClient.cs


注:本文中的System.IO.StreamReader.ReadAsMany方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。