Partager via


Generated Proxy Classes defaultUserContext Property

Gets or sets the default user context for the generated proxy class and its instances. This property exists at run time after the proxy class has been generated by the server.

Note

To get or set property values for client API properties, you must call property accessor methods that are named with the get_ and set_ prefixes. For example, to get or set a value for a property such as cancel, you call the get_cancel or set_cancel methods.

// Syntax for the generated proxy class.
var userContext = MyNameSpace.MyServiceProxy.get_defaultUserContext(); 
MyNameSpace.MyServiceProxy.set_defaultUserContext(value);

// Syntax for a proxy instance.
var userContext = myServiceProxy.get_defaultUserContext(); 
myServiceProxy.set_defaultUserContext(value);

Parameters

Parameter

Description

value

The user context information that is associated with the Web service call. value can be null, any primitive type, or a JavaScript object.

Return Value

The user context information that is associated with the Web service request, if any; otherwise, null.

Remarks

The user context object can be passed as a parameter to the succeeded or failed callback functions during any call to a Web service method. For more information, see Generated Proxy Classes Succeeded Callback Function and Generated Proxy Classes Failed Callback Function.

If you pass a user context when you call a Web service method, the passed value overrides the value that is set by using the defaultUserContext property.

Example

The following example shows how to set and get the defaultUserContext property for the generated proxy class and for a proxy instance.

// This function sets and gets the default user context
// for the Web service generated proxy class.
function AssignUserContext() 
{
    // Define the user context.
    var userContext = "Proxy context.";

    // Set the default user context.
    Samples.AspNet.UsingProxyClass.set_defaultUserContext(userContext);

    // Get the default user context.
    userContext = 
        Samples.AspNet.UsingProxyClass.get_defaultUserContext();

    // Display the user context.
    DisplayMessage("The user context is: " + userContext);
}
// This function sets and gets the default user context
// for an instance of the Web service generated proxy class.
function AssignInstanceUserContext() 
{
    // Define the user context.
    var userContext = "Proxy instance context.";
    // Create an instance of the proxy class.
    var proxyInstance = 
        new Samples.AspNet.UsingProxyClass();

    // Set the default user context.
    proxyInstance.set_defaultUserContext(userContext);

    // Get the default user context.
    userContext = 
        proxyInstance.get_defaultUserContext();

    // Display the user context.
    DisplayMessage("The user context is: " + userContext);
}

See Also

Reference

Generated Proxy Classes Succeeded Callback Function

Generated Proxy Classes Failed Callback Function

Concepts

Sys.Net.WebServiceProxy Class