1

我正在使用 WCF REST 4.0 默认端点配置,在客户端上我使用的是 WebClient。无论如何要为 WebClient 配置新的超时值?

4

1 回答 1

2

我已经使用了一个在这里找到的自定义类。

public class MyWebClient: WebClient
{
   //time in milliseconds
    private int timeout;
   public int Timeout
   {
           get {
               return timeout;
           }
           set {
               timeout = value;
           }
    }

    public MyWebClient()
    {
           this.timeout = 60000;
    }

     public MyWebClient(int timeout)
    {
           this.timeout = timeout;
    }

    protected override WebRequest GetWebRequest(Uri address)
     {
           var result = base.GetWebRequest(address);
           result.Timeout = this.timeout;
           return result;
    }
}

大体思路是覆盖内部WebRequest的超时时间。伟大的 !

于 2012-09-18T12:42:17.760 回答