Forum Discussion

francisco_garci's avatar
francisco_garci
Occasional Contributor
9 years ago

Cannot assign an object to a variant array in a Web Service Request

Hello,

 

I have a Web Service which has a similar structure:

 

<Body>

             <WebMethod1>

                                        <VariantOfObject1>

                                                                    <Object1>

                                                                                     <node1/>

                                                                                     <node2/>

                                                                                     <node3/>

                                                                    </Object1>

                                                                    <Object2>

                                                                                     <node1/>

                                                                                     <node2/>

                                                                                     <node3/>

                                                                    </Object2>

                                        </ArrayOfObject1>

             </WebMethod1>

</Body>

 

And in order to assign an object to each Array entry, I use the following code:

 

function RequestObject ()

{

 

var TypeFactory;

var Result;

 

TypeFactory = WebService.MyWS.TypeFactory;

Result = TypeFactory.ArrayOfObject;
Result.Object = BuiltIn.CreateVariantArray(0,1);

 

for (var i=0; i<2;i++)

{

Result.Object(i) = TypeFactory.Object;

Result.Object(i).node1 = "a";

Result.Object(i).node2 = "a"

Result.Object(i).node3 = "a"

}

return Result;

}

 

With this code, the object generates just fine, but when I try to assign the generated object to an entry of the Array, I see that the array doesnt save the object in each entry and appears as a "undefined" value and and the data type is "String", instead of "(Object)". Can you guys help me out with this please? I have looked everywhere and I dont seem to find the answer nor I can find a work around. If you need extra information, I will gladly give it.

9 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    a) Objects cannot be transferred by Web Services, but only their serializations (which are usually strings);

    b) Result.Object = BuiltIn.CreateVariantArray(0,1);

    this creates an array with two elements (with indexes 0 and 2) but in the cycle

    for (var i=0; i<2;i++)

    you are trying to address three elements. (BuiltIn.VarArrayLowBound() and BuiltIn.VarArrayHighBound() are recommended to avoid such mistakes);

    c) Are you using the code generated by TestComplete or crafted by yourself?

     

    If you can send me (through this thread or privately) the contents of the WebServices folder of your project I will try to help you with the code.

  • francisco_garci's avatar
    francisco_garci
    Occasional Contributor

    Hi Alex,

     

    Thank you for your answer, now I used the code generated by test complete with the "Code" button and got the following:

     

    function ArrayOfProgrammeMemberActivity()
    {
    var Result;
    var TypeFactory;
    //Get the type factory for the web service
    TypeFactory = WebServices.MemberWebService.TypeFactory;
    Result = TypeFactory.ArrayOfProgrammeMemberActivity;
    //Generating the array property. Choose the lower and upper array bounds that meet your needs
    Result.ProgrammeMemberActivity = BuiltIn.CreateVariantArray(0, 10);
    var i;
    for(i = BuiltIn.VarArrayLowBound(Result.ProgrammeMemberActivity, 1); i <= BuiltIn.VarArrayHighBound(Result.ProgrammeMemberActivity, 1); i++)
    {
    Result.ProgrammeMemberActivity(i) = TypeFactory.ProgrammeMemberActivity;
    Result.ProgrammeMemberActivity(i).PmaType = "";
    Result.ProgrammeMemberActivity(i).Merged = "";
    Result.ProgrammeMemberActivity(i).Cancelled = "";
    Result.ProgrammeMemberActivity(i).RecordLocator = "";

    }

    return Result;

    }

     

    This was generated by test complete but I still get an array with "undefined" entries, the example I posted at the begging was an example based on this code, sorry if I didnt post it to begin with. I hope this helps you out more Alex in uderstanding the issue. I attach an image of what test complete gives me as a result when I run this code.

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      As I said, it's not easy to provide you with the actual code without having either the service wsdl file or the contents of the WebServices subfolder of TestComplete project, but the general approach is:

      -- you create the request. This gives you the request object and its parameters (first level);

      -- if some of the first-level parameters are complex ones, then you must create and initialize their structure and assign the structure to the parameter.

       

      You might consider the sample from the <Users>\Public\Documents\TestComplete 11 Smaples\Common\Web Service Testing folder and adopt it to your case .

       

  • francisco_garci's avatar
    francisco_garci
    Occasional Contributor

    Hi Alex,

     

    I tried many options and still can't get it to work. I could provide the WSDL URL we use, where can I share with you?

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      Try to send me a private message (click the link with my name and on the opened About window look for the 'Send this user a private message.' link in the Contact Me section on the right).  If the url is public then you can send just a url. If it is private (i.e. accessible only from within your network), then I will need the contents of the WebServices subfolder of your test project.

  • francisco_garci's avatar
    francisco_garci
    Occasional Contributor

    Hi,

     

    For the guys looking for the answer, it seems my code doesn't work with Jscript, but it works with VBscript. I'm going to switch to VBscript for my Web Service.

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      For those monitoring this thread :)

       

      Clarification from my point of view:

      a) My opinion is that (for this given case) JScript code actually works exactly like its VBScript equivalent. The problem seems to be in the debugger's expression evaluator that does not properly displays the values for some inspected objects. But the objects itself are created properly. I think that this problem should be reported to Support;

       

      b) I think that VBScript is the worst choice for Web Services testing. The reason is that it does not support exceptions handling (and On Error GoTo Next is extremely inconvenient for the given case) and this may cause coding problems for the negative tests (the tests that use incorrect or incomplete data for purpose) when an exception is expected from the tested web service.