Forum Discussion

pkolcon's avatar
pkolcon
New Contributor
9 years ago

TestComplete: Adding headers to Message bug?

Hi,

 

I'm trying to test my WebServices over net.tcp protocol, so I've choosen TestComplete to get it done.

 

I do not want to create XML files manually, so I'm using simple call to service methods. Most of them need custom header with authorization details, so I've attached to OnWebServiceRequest method, and using 

 

WebServiceHelperObj.AddHeader(NameNamespaceValue)

 

method I'm trying to get it done. Now,the problem:

 

After using the method mentioned above, my header does not look like it should. An example:

 

Calling : 

Helper.AddHeader("UserID", "http://tempuri.org/", "jsmith");

Helper.AddHeader("Password", "http://tempuri.org/", "25jeL3n");

 

results in header:

 

<s:Header>
  <a:Action s:mustUnderstand="1">http://tempuri.org/MethodContract/MethodName</a:Action>
  <a:MessageID>urn:uuid:9244f15d-ae34-422c-ad9d-cd32f616b042</a:MessageID>
  <a:ReplyTo>
         <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<UserID xmlns="http://tempuri.org/">
        <UserID>jsmith</UserID>
</UserID>
<Password xmlns="http://tempuri.org/">
      <Password>25jeL3n</Password>
</Password>
<a:To s:mustUnderstand="1">net.tcp://ADDRESS.svc</a:To>
</s:Header>

 

As you can see, the header elements are nested, which is not the result I would want to achieve.

 

Second problem: the header i require to add is nested structure, as follows:

 

<s:Header>

    <MyHeader>

       <UserName>NAME</UserName>

       <Password>Password</Password>

    </MyHeader>

</s:Header>

 

how can I achieve this using AddHelper method?

8 Replies

    • pkolcon's avatar
      pkolcon
      New Contributor

      Hello and thanks for the reply,

       

      As you might notice, the requirement for communication with Service is using net.TCP protocol. Does SoapUI NG Pro support it? Because, when I was searching for the informations about it, I couldn't find any confirmation - more than that, I've seen that previous version of SoapUI had no support for net.TCP. 

       

      So, will SoapUI NG Pro be a better solution in my case? 

  • icenamor's avatar
    icenamor
    Occasional Contributor

    Hi, 

    I try to reproduce the same code as appear https://support.smartbear.com/testcomplete/docs/app-testing/web/services/custom-headers.html 

     

    1) I add a General event -> GeneralEvents_OnWebServiceRequest

    2) Generate the script in python 

    def GeneralEvents_OnWebServiceRequest(Sender, Request, Helper, RequestInfo): 


    Helper.AddHeader('USER', 'http://auth.', '1014531');
    Helper.AddHeader('PASSWORD', 'http://auth', '4QrcOUm6Wau+VuBX8g+IPg==');

     

    def Main():

       webservice.example.method()

     

    and the solution is: no head included and when I run the method GeneralEvents_OnWebServiceRequest appear:

    AttributeError: 'NoneType' object has no attribute 'AddHeader'      14:25:40          Normal                                   0,00

    Run Script Routine     Unit1 - GeneralEvents_OnWebServiceRequest      ...         Runs a script routine.

     

     

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Based upon what you have posted, it appears that you have added the event handler as a script routine call to a keyword test.  That is not how event handlers work.  You should be running ONLY what you have declared as def Main().  The event handler will be triggered automatically when the request is made.  This is why you're getting the error your getting: there is no "Helper" to add a header to because you're running the event handler directly.

      As for the recursive call... You probably have the keyword test you're trying to run call a method which in turn calls the keyword test.  That's what recursion is... Especially if you are having the keyword test call the event handler and the event handler calling Main which triggers the event handler.

      The solution in the article you linked only runs "Main".  No other code is directly executed.

       

      If you need further help, please post a screenshot of the KeywordTest you are attempting to run so we can help you correct that.

  • icenamor's avatar
    icenamor
    Occasional Contributor

    A recursive call to the keyword test has been detected.

     

  • icenamor's avatar
    icenamor
    Occasional Contributor

    The recursive problem is solved. The link for the code was not correct, however the problem with not type is not solved.

    Here attach the problem. I hide the confidence data for my company.  I tested the data with SoaPUI and the webservice with this data is working. 

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Here's my guess....  That somehow, something is erroring before the OnWebServiceRequest event is being triggered that is causing the Helper object to not be instantiated.

       

      I'm curious as to what the "Request" body is when you're in that OnWebServiceRequest.  It's possible that the request itself is not being generated properly... 

       

      I'd drop a breakpoint on "Log.Message('start header')" and then, with the execution paused, investigate "Request" and see what's actually in there.

      • icenamor's avatar
        icenamor
        Occasional Contributor

        Yes, the problem is causing the Helper object to not be instantiated. It is something does not appear in the tutorial. I have another problem now. 

        Thanks for the help.