生成的代理类 timeout 属性

更新:2007 年 11 月

获取或设置生成的代理类及其实例的超时间隔。此属性在服务器已生成代理类之后在运行时存在。

说明:

若要获取或设置客户端 API 属性的属性值,必须调用以 get_set_ 为名称前缀的属性访问器方法。例如,若要获取或设置属性 cancel 的值,需要调用 get_cancelset_cancel 方法。

// Syntax for the generated proxy class.
var timeout = MyNameSpace.MyServiceProxy.get_timeout(); 
MyNameSpace.MyServiceProxy.set_timeout(value);

// Syntax for a proxy instance.
var timeout = myServiceProxy.get_timeout(); 
myServiceProxy.set_timeout(value);

参数

参数

说明

value

超时间隔(以毫秒为单位)。

返回值

超时值(以毫秒为单位)。

备注

timeout 属性获取和设置在调用 Web 服务方法的过程中,在 Web 请求超时之前,网络执行器应等待的时间(以毫秒为单位)。通过设置超时间隔,可以确保挂起的 Web 请求以比在请求期间等待基础网络堆栈超时更快的速度将控制权返回给您的代码。如果以前没有设置 timeout 间隔,则该属性返回 Sys.Net.WebRequestManager.defaultTimeout 属性的值。

网络执行器将 0 值理解为由基础网络堆栈负责等待超时间隔。

示例

下面的示例演示如何获取和设置生成的代理类及其代理实例的 timeout 属性。

// This function sets and gets the timeout
// for the Web service generated proxy class.
function AssignTimeout() 
{
    // Define the timeout (100 msecs).
    var timeout = 100;

    // Set the timeout.
    Samples.AspNet.UsingProxyClass.set_timeout(timeout);

    // Get the timeout.
    timeout = 
        Samples.AspNet.UsingProxyClass.get_timeout();

    // Display the timeout.
    DisplayMessage("The proxy timeout is: " + timeout + " msecs.");
}

// This function sets and gets the timeout for an 
// instance of the Web service generated proxy class.
function AssignInstanceTimeout() 
{
    // Define the timeout (1000 msecs).
    var timeout = 1000;
    // Create an instance of the proxy class.
    var proxyInstance = 
        new Samples.AspNet.UsingProxyClass();

    // Set the timeout.
    proxyInstance.set_timeout(timeout);

    // Get the timeout.
    timeout = proxyInstance.get_timeout();

    // Display the timeout.
    DisplayMessage("The proxy instance timeout is: " + timeout + " msecs.");
}

请参见

概念

Sys.Net.WebServiceProxy 类