当响应的生成时间超过 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 = "";
}
我尝试了几种建议的方法来设置适当的超时,但不幸的是没有成功。你能帮我解决这个问题吗?