与webclient超时 [英] Timeout with webclient

查看:77
本文介绍了与webclient超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个WCF服务,如:



Hi,

I have a WCF service like:

[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, UriTemplate = "SelectQueryResult")]
string GetSelectQueryResult(ClsPagingInfo objClsPagingInfo);





我在一个MVC项目中消费它,比如:





And I consuming it in a MVC project like:

objClsPagingInfo.iPageSize = Convert.ToInt32(PageSize);
                   objClsPagingInfo.iCurrentPageIndex = Convert.ToInt32(CurrentPageIndex);
                   objClsPagingInfo.iPageCount = 1000;
                   objClsPagingInfo.sQuery = txtQuery.Trim();

                   DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ClsPagingInfo));
                   MemoryStream ms = new MemoryStream();
                   ser.WriteObject(ms, objClsPagingInfo);
                   string data = Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length);

                   WebClient webClientNewTicket = new WebClient();
                   webClientNewTicket.Headers["Content-type"] = "application/json";
                   webClientNewTicket.Encoding = Encoding.UTF8;
                   string sResultData = webClientNewTicket.UploadString("http://localhost:50750/TnsEspService.svc/SelectQueryResult", "POST", data);

                   sResultDataReturn = JsonConvert.DeserializeObject<string>(sResultData);
                   DataTable ResultDataTable = (DataTable)JsonConvert.DeserializeObject(sResultDataReturn, (typeof(DataTable)));

                   ViewBag.DataTableTest = ResultDataTable;





当WCF返回小数据时它工作正常但是当WCF返回大量数据时它通过超时错误。



请为此问题提出一些解决方案。



谢谢,



It works fine when WCF returns small data but when WCF returns a huge data then It through "Timeout error".

Please suggest some solution for this issue.

Thank you,

推荐答案

设置更高的接收超时可能是一个解决方案



在绑定上配置超时值 [ ^ ]
setting a higher receive timeout could be a solution

Configuring Timeout Values on a Binding[^]


这篇关于与webclient超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆