微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WebException 操作在 100 秒后超时 C#

如何解决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 举报,一经查实,本站将立刻删除。