为什么调用Web服务方法几乎会立即超时?

时间:2012-11-14 21:52:17

标签: web-services .net-4.0 windows-server-2003

使用.NET 1.1的此Web服务的生产版本没有此问题。这是在Windows Server 2003上运行.NET 4.0的测试环境中。

我遇到一个问题,我收到以下异常:

    System.Net.WebException: The operation has timed out    
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)    
at System.Net.HttpWebRequest.GetRequestStream()    
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)    
at HTP.RHIO.PIRManager.TargetWS.PIRService.Upload(Transmission t_request)    
at HTP.RHIO.PIRManager.Manager.PIRManager.Upload(Transmission request)

当我的webservice的Upload方法调用另一个webservice的Upload方法时,会发生这种情况。超时几乎立即发生,大约1/3秒(注意log_datetime列)

Log

代码:(它在异常输出中记录间隔的行尚未实现,这就是为什么它没有出现在输出中。它应该落到默认值interval = 60 [* 1000] )

int interval = 0;                                                                           
try 
{

    try
    {
        interval = Convert.ToInt16(System.Configuration.ConfigurationSettings.AppSettings["RealTimeTimeOutSeconds"]);
    }
    catch(Exception ex)
    {
        interval = 60;
    }

    interval = interval * 1000;
    target.Timeout = interval;
    trans = target.Upload(trans);
    }                               
    catch(System.Net.WebException ex)
    {               
        request.TransmissionHeader.MessageCode = GetReturnMessageCode(ex); 
        request.TransmissionHeader.Message = ex.Message;
        Log(request.TransmissionHeader, "Upload", "FAILED", "(Timeout = " + interval.ToString() + ") " + ex.ToString(), 1);

        trans = TA1forFailedRealtimeUpload(trans.TransmissionHeader);                                       
        request = ConvertToLocal(trans, request);
        Log(request.TransmissionHeader, "Upload", "SENDING", "Responding to sender with TA1", 1);
        return request;                             
    }
}

并从我的网站服务的web.config文件:

<httpRuntime executionTimeout="600" maxRequestLength="2000000"/>

1 个答案:

答案 0 :(得分:0)

Convert.ToInt16可能无法满足您的期望。来自the manual;

  

返回值

     

类型:System.Int16
  一个16位有符号整数,相当于值中的数字,如果value为null,则为或0(零)。

如果您的配置中未设置RealTimeTimeOutSeconds,您将转换为NULL,这将导致零超时。