Calling Web Service Methods That Use Out Parameters

Applies to TestComplete 14.93, last modified on October 12, 2021

A web service method may use out or in/out parameters. Testing these methods have the following specifics:

  • In WSDL terms, the return value of a function is a parameter of the out type. So, in WSDL terms, the method that returns a value and uses one or more out (or in/out) parameters is treated as a method that has two (or more) out parameters. From the WSDL information it is impossible to determine which of these parameters should be treated as a return value and which should be treated as a parameter.

    To work around the problem, TestComplete considers these methods as routines that do not return any value. These procedures contain all the method parameters plus one more out parameter that corresponds to the method’s result value. The name of this parameter contains the method’s name and the word Result. For instance, the following C# method --

    C#

    public bool MyTestMethod(int Param1, int Param2, out int ParamA, out int ParamB, out int ParamC)

    -- will be treated as --

    JavaScript, JScript

    function MyTestMethod(int Param1, int Param2, bool MyTestMethodResult, int ParamA, int ParamB, int ParamC);

    Python

    def MyTestMethod(Param1: int, Param2: int, MyTestMethodResult: bool, ParamA: int, ParamB: int, ParamC: int);

    VBScript

    Sub MyTestMethod(Param1 as Integer, Param2 as Integer, MyTestMethodResult as WordBool, ParamA as Integer, ParamB as Integer, ParamC as Integer)

    DelphiScript

    procedure MyTestMethod(Param1 : Integer; Param2 : Integer; MyTestMethodResult : WordBool; ParamA : Integer; ParamB : Integer; ParamC : Integer);

    C++Script, C#Script

    function MyTestMethod(int Param1, int Param2, bool MyTestMethodResult, int ParamA, int ParamB, int ParamC);

    Pay special attention to the MyTestMethodResult parameter. It corresponds to the method’s return value (method name + Result). This parameter does not exist in C# syntax. TestComplete adds it since the method uses out parameters.

    If a method does not return any value and uses one out parameter, TestComplete will treat this method as a function and will treat the parameter as the function’s return value.

  • You call web services’ methods that use out parameters in the same manner as you call ordinary methods. After a call, you can check the values assigned to the out parameters.

    Note, however, that JScript, Python, C++Script and C#Script do not support out parameters, so to obtain the values returned in these parameters, you should parse the web services response.

    To obtain scripting access to the response’s contents, you can use the LastResponse property of the WebService object that corresponds to the tested web service. This property returns an object that implements the IXMLDOMDocument interface and that corresponds to the SOAP response’s data (SOAP uses XML and the response contents match the Microsoft XML DOM model).

    You can use methods and properties of the IXMLDOMDocument object to parse the response’s data and to obtain the values of the out parameters. However, this approach requires you to know the names of the elements holding the parameters’ values and the elements structure.

    To simplify access to parameters, use the CreateWebServiceInfoFromItem method of the WebServices object and the WebServiceInfo object returned by this method. The following example demonstrates how you can use these methods and objects to get easy access to parameter values:

    JavaScript, JScript

    function Test()
    {
      var a, b, c, r;
      var wsiObj, respObj;

      // Call the method
      WebServices.WebService1.MyTestMethod(2, 3, r, a, b, c);

      // After the call the r, a, b and c variables will not contain any values,
      // since JScript does not support out parameters
      
      // Obtain the WebServiceInfo object
      wsiObj = WebServices.CreateWebServiceInfoFromItem("WebService1");

      // Parse the response
      respObj = wsiObj.ParseResponse("MyTestMethod", WebServices.WebService1.LastResponse);

      // Post the result value and out parameters to the log
      Log.Message(aqConvert.VarToStr(respObj.MyTestMethodResult)); // Result value
      Log.Message(aqConvert.VarToStr(respObj.ParamA)); // ParamA parameter
      Log.Message(aqConvert.VarToStr(respObj.ParamB)); // ParamB parameter
      Log.Message(aqConvert.VarToStr(respObj.ParamC)); // ParamC parameter
    }

    Python

    def Test():
      # Call the method
      WebServices.WebService1.MyTestMethod(2, 3, r, a, b, c);
    
      # After the call the r, a, b and c variables will not contain any values,
      # since Python does not support out parameters
      
      # Obtain the WebServiceInfo object
      wsiObj = WebServices.CreateWebServiceInfoFromItem("WebService1");
    
      # Parse the response
      respObj = wsiObj.ParseResponse("MyTestMethod", WebServices.WebService1.LastResponse);
    
      # Post the result value and out parameters to the log 
      Log.Message(aqConvert.VarToStr(respObj.MyTestMethodResult)); # Result value
      Log.Message(aqConvert.VarToStr(respObj.ParamA)); # ParamA parameter 
      Log.Message(aqConvert.VarToStr(respObj.ParamB)); # ParamB parameter
      Log.Message(aqConvert.VarToStr(respObj.ParamC)); # ParamC parameter

    VBScript

    ' VBScript supports out parameters,
    ' so there is no need to use specific objects
    ' or methods to obtain their values.

    DelphiScript

    { DelphiScript supports out parameters,
      so there is no need to use specific objects
      or methods to obtain their values.}

    C++Script, C#Script

    function Test()
    {
      var a, b, c, r;
      var wsiObj, respObj;

      // Call the method
      WebServices["WebService1"]["MyTestMethod"](2, 3, r, a, b, c);

      // After the call the r, a, b and c variables will not contain any values,
      // since C++Script and C#Script do not support out parameters
      
      // Obtain the WebServiceInfo object
      wsiObj = WebServices["CreateWebServiceInfoFromItem"]("WebService1");

      // Parse the response
      respObj = wsiObj["ParseResponse"]("MyTestMethod", WebServices["WebService1"]["LastResponse"]);

      // Post the result value and out parameters to the log
      Log["Message"](aqConvert["VarToStr"](respObj["MyTestMethodResult"])); // Result value
      Log["Message"](aqConvert["VarToStr"](respObj["ParamA"])); // ParamA parameter
      Log["Message"](aqConvert["VarToStr"](respObj["ParamB"])); // ParamB parameter
      Log["Message"](aqConvert["VarToStr"](respObj["ParamC"])); // ParamC parameter
    }

    Note: In order for TestComplete to be able to parse the response contents correctly, the WSDL information stored in the WebService project element must match the actual WSDL data of the tested web service. If the stored and actual information differs (for instance, if the stored parameter names differ from the actual parameter names), the parsing will work incorrectly. To update the stored WSDL information, open the WebService editor and press Refresh in it.
  • When a web service’s method returns an array, this array has the format of a Visual Basic safe array. In order to use such an array in JScript, C#Script or C++Script, you need to convert the array to a standard JScript array by using the toArray method of the variant array:

    JScript, C#Script, C++Script

    //Convert the variant array to the JScript array format
    var MyArray = VariantArray.toArray();

    //Iterate through array elements
    for(var i = 0; i < MyArray.length; i++)
    {
     Log.Message(MyArray[i]);
    }

See Also

Creating Web Service Tests
Testing Web Services - Overview
Testing Web Services

Highlight search results