Forum Discussion

samuelskanberg's avatar
samuelskanberg
Occasional Contributor
13 years ago

How to set global http headers

Hello,

I am using SoapUI 4.5.2 (open source version). I am using a web service (WCF) which require password and user id for each WS call in the header. For each WS method call I have to put in the password header and the user id header. I also have to set WS-Adressing for each WS call: "Add default wsa:Action" and "Add default wsa:To".

First I will open the WS method, then I will click the "Headers" tab beneath the input window. I will click the "+" to add a HTTP header, first I will add UserID and set a User ID, then I will add the password header.

Secondly, I will click the WS-A tab, check the "Add default wsa:Action" checkbox and then check the "Add default wsa:To" checkbox.

I have to do this for each WS method which is kind of annoying. Is there any way to set these http headers and WS addressing settings globally?

Thank you for your help!

Best regards,
Samuel

7 Replies

  • nmrao's avatar
    nmrao
    Community Hero
    It is possible to set the userid and password and endpoint etc details at the service interface, and assign to all test request. Is this what your are looking for?
  • samuelskanberg's avatar
    samuelskanberg
    Occasional Contributor
    No, not really. Since I am authenticating in a different way it doesn't work.

    I tried right clicking the wsHttps and chose "Show interface viewer" --> Clicked "Service endpoints" --> Entered my UserId for "Username" and Password for "Password". I then clicked "Assign" and chose "All requests". (I am assigning to all normal requests, I don't need test requests right now). I then tried calling some WS method (which I had removed the assigned UserId and Password headers for) but it didn't work:


    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
    <s:Header>
    <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
    </s:Header>
    <s:Body>
    <s:Fault>
    <s:Code>
    <s:Value>s:Sender</s:Value>
    </s:Code>
    <s:Reason>
    <s:Text xml:lang="en-GB">Please provide userID and password in Header information.</s:Text>
    </s:Reason>
    </s:Fault>
    </s:Body>
    </s:Envelope>


    So in the web service I'm using, I have to put "UserID" in as a header parameter. In the settings you suggested, it's "Username". I don't really know what the difference are between what you suggested and by adding custom header to each WS method.
  • nmrao's avatar
    nmrao
    Community Hero
    Is this how you would like to send the request?

    POST http://www.webservicex.com/currencyconvertor.asmx HTTP/1.1
    Accept-Encoding: gzip,deflate
    Content-Type: text/xml;charset=UTF-8
    SOAPAction: "http://www.webserviceX.NET/ConversionRate"
    userID: dfdf
    password: dfd
    Content-Length: 345
    Host: www.webservicex.com
    Connection: Keep-Alive
    User-Agent: Apache-HttpClient/4.1.1 (java 1.5)


    Or probably you can post the raw request of correct service operation which works for you.
  • samuelskanberg's avatar
    samuelskanberg
    Occasional Contributor
    Yeah, exactly! That's how I want to do it. I have added the header by clicking on the "+" to add userId and Password. After I have done that and I click the "Raw" tab, I got the result you posted.

    Is it possible to set those additional (userId and Password headers) for all web methods?
  • nmrao's avatar
    nmrao
    Community Hero
    Understood the pain you are explaining about in the original post. How many of such requests to be updated? It would be worth to do it programatically if there are more of such.
  • samuelskanberg's avatar
    samuelskanberg
    Occasional Contributor
    It's 35 of them so it's definitely worth doing programatically if it can't be done with settings.

    I saw some suggestions on the web for settings headers for test request but that's not really what I want, I want to set the headers for my "normal" requests.

    Here is one suggestion that uses a groovy script to set the headers for all test requests: viewtopic.php?t=3746

    Is there a way to run a groovy script for all the "normal" requests? And if so, what object should I use to get to the "normal" requests? I guess the testRunner object won't really do the trick, will it?