result Object

This topic documents a feature of Binary Behaviors, which are obsolete as of Internet Explorer 10.

This object exposes the results and brief diagnostics for an invocation of the callService method.

Members Table

The following table lists the members exposed by the result object.

Property Description
error A Boolean property created by the WebService behavior after calling the callService method.
id A property of the result object that has a unique value which corresponds to a specific execution of the callService method.
raw Exposes the raw SOAP data packet returned by the Web Service after invoking the callService method.
SOAPHeader An Array of SOAP headers that overrides the default SOAP header generated by the WebService behavior.
value A property of the result object that is created at run time.
Object Description
errorDetail This object is exposed by the result object if an error is encountered from an invocation of the callService method. The properties of errorDetail provide detailed information and diagnostics on the error.

Remarks

The syntax used to reference the result object depends on the approach used to handle the result from a method call. If a callback handler function is used, the result is passed as the first parameter of the callback function, and is referenced directly. If an event handler for the onresult event is used, the result is exposed from the event object.

See the examples section below, where examples are provided for both result handling approaches.

A web service that uses a reference variable as a parameter is a special case. This is because Microsoft JScript and Microsoft Visual Basic Scripting Edition (VBScript) do not support reference parameters while the WebService Behavior does. Values passed from the web service to the client code will not be accessible directly through the value property of the result object, as in the other cases. Consider the following example of a function in a web service, written in C#.

public String ServerFunction(String S1, ref String S2)
{
    S2 = "New";
    return "ReturnString2";
}

In this example, the changed reference value is accessible in the client code by result.value["S2"]. The value returned by the web service is accessible in the client code by result.value["ServerFunctionResult"].

Note  The return value of the function is read by appending "Result" to the name of the function.

Examples

If a callback handler function is specified as the first parameter of the callService method, then the result object is passed as the parameter to the callback handler function. The following code snippet demonstrates this technique.

<SCRIPT language="JavaScript">
var iCallID;

function init()
{
    // Establish the friendly name "MyMath" for the WebServiceURL
    service.useService("/services/math.asmx?WSDL","MyMath");
    // The following uses a callback handler named "mathResults"
    iCallID = service.MyMath.callService(mathResults, "add", intA, intB);
}

function mathResults(result)
{
    // if there is an error, and the call came from the call() in init()
    if(result.error)
    {
        // Pull the error information from the event.result.errorDetail properties
        var xfaultcode   = result.errorDetail.code;
        var xfaultstring = result.errorDetail.string;
        var xfaultsoap   = result.errorDetail.raw;

        // Add code to handle specific error codes here
    }
    // if there was no error
    else
    {
        // Show the arithmetic
        alert(intA + ' + ' + intB + " = " + result.value);
    }
}
</script>
<body onload="init()">
<div id="service" style="behavior:url(webservice.htc)">
</div>
</body>

If a callback handler function is not used, then the event object of the onresult event exposes the result object, which can be referenced as follows:

<SCRIPT language="JavaScript">
var iCallID;

function init()
{
    service.useService("/services/math.asmx?WSDL","MyMath");
    iCallID = service.MyMath.callService("add",5,6);
}

function onWSresult()
{  
    if((event.result.error)&&(iCallID==event.result.id))  
    {    
        var xfaultcode   = event.result.errorDetail.code;
        var xfaultstring = event.result.errorDetail.string;    
        var xfaultsoap   = event.result.errorDetail.raw;
        document.writeln("ERROR. Method call failed!");
        document.writeln("Call ID:" + iCallID);
        document.writeln("Fault Code:" + xfaultcode);
        document.writeln("Fault String:" + xfaultstring);
        document.writeln("SOAP Data:" + xfaultsoap);
    }
    else if(event.result.error == false)
    {
        document.writeln("Result received without errors!");
    }
}
</script>
<body onload="init()">
<div id="service" style="behavior:url(webservice.htc)" onresult="onWSresult()">
</div>
</body>

Applies To

WebService, onresult

See Also

callService, useService, Using the WebService Behavior, About the WebService Behavior