WebException 操作在 100 秒后超时 C#

问题描述

当响应的生成时间超过 100 秒时,我在调用特定 WS 时遇到问题。

遵循我的代码

try {
    XmlDocument soapEnvelopeXml = CreateSoapEnvelope(request);
    HttpWebRequest webRequest = CreateWebRequest(url,action,username,password);
    webRequest.ContinueTimeout = 200000;
    webRequest.ReadWriteTimeout = 200000;
    InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml,webRequest);  
    // begin async call to web request.
    IAsyncResult asyncResult = webRequest.BeginGetResponse(null,null);

    // suspend this thread until call is complete. You might want to        
      if( asyncResult.AsyncWaitHandle.WaitOne(-1) )
        {
            //MessageBox.Show("Call completed!!!");
            // get the response from the completed web request.
            string soapResult;
            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
                {           
                    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                    {
                        soapResult = rd.ReadToEnd();
                    }
                    response = soapResult;
                    success = true;
                    errMessage = "";
                }
        }
          else
                {
                    MessageBox.Show( "Call didn't complete in 180 seconds" );
                    errMessage = "Call didn't complete in 180 seconds";
                    throw new Exception(errMessage);
                }       
}
  catch(Exception ex) {
            errMessage = ex.GetType().Name + " " + ex.Message;
            success = false;
            response = "";            
        }

我尝试了几种建议的方法来设置适当的超时,但不幸的是没有成功。 你能帮我解决这个问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)