Salesforce and soapUI – Testing WebServices directly

In a previous post I talked about writing webservices for Salesforce. In this post I’ll discuss how to test your webservice with soapUI without having to write any additional code.

Getting soapUI

You will need to install the Open Source version of soapUI from their sourceforge.  Go ahead, I’ll wait….

Getting the WSDLs

Now that you have soapUI installed we need to download our WSDLs.  You’ll need the Enterprise WSDL which can be found at Setup-Develop-API.  And you’ll need the WSDL for your webservice which can be found at Setup-Develop-Apex Classes, then find your class and click the WSDL link next to it.  I suggest downloading them into a WSDL folder just for organization.

Setting up soapUI

Now that we’ve got all of our parts we need to create a new soapUI project.  If you are testing multiple webservices I suggest you only create one soapUI project and import the additional webservices into it.  This will make updating the enterprise WSDL easier, and will make your life less stressful.

Right-click on Projects and select New soapUI Project and fill out the form with your information.  Your intial WSDL should be the enterprise WSDL.  You will at the very least want to have Create Requests checked.  You can choose the other later if you want to.

After creating the new project you will see a section called SoapBinding with several methods below it.  These are standard Salesforce methods that are provided by the Salesforce Enterprise WSDL. Let’s ignore these for right now, and import our webservice.  To add a new WSDL right-click on the project name, Salesforce in our case, and select Add WSDL.

Then we want to choose our webservices WSDL

Using soapUI

Now that we are all setup, let’s test our webservice.  First we need to login to Salesforce and get our session Id.  Under the SoapBinding list, expand login and choose Show Request Editor.  After opening the request editor we need to remove the extra headers we don’t need, and fill in our username and password.

Then press the “play” button to send the request

Now in the resulting XML we can pull out our session Id

Copy the session Id and we will use it to make a request to our webservice.  In the example below I am calling the search method on my CaseAPI.  Again, we can remove almost all of the header out of the request.  The only section we need to leave is the SessionHeader and SessionId.

Then fill in the request to your webservice.  This will all depend on how yours is designed.  In the webservice call below, we pass in two context objects.  One takes in an ssoName and the other takes in a searchString.  Then as before click the “play” button and you’ll get your response back.

Conclusion

SoapUI is a great tool to help test webservices out.  You can use it to build up tests, but that’s another post.  I use it all of the time to verify that Salesforce is returning the correct data from my webservice instead of trying to write against the webservice and trying to determine if my client is messing up.

This entry was posted in developement, salesforce and tagged , , , , , , . Bookmark the permalink.

14 Responses to Salesforce and soapUI – Testing WebServices directly

  1. Ladu kishore Dash says:

    Good one ,Very useful thanks Patrick for sharing this.

  2. AlexF says:

    Patrick,

    Perhaps you’d like to share your experience using soapUI in the future as a guest blog for @SmartBear

    soapUI users group on Linkedin if you’re interested: http://www.linkedin.com/groups?home=&gid=4082922

    Best,
    Alex

  3. Maulik says:

    Patrick,

    After copying the sessionId in my application, if I query lets say describeGlobal operation, I am getting following exception:

    UNKNOWN_EXCEPTION
    UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService

    UNKNOWN_EXCEPTION
    Destination URL not reset. The URL returned from login must be set in the SforceService

    Based on docs, it seems we need to put serverUrl as well. Have you tried doing it? After putting it, I still dont get it.

  4. pcon says:

    I’ve not ever had to put in a ServerURL. I believe it uses the URL provided in your services WSDL. If you look in the last screenshot, mine has https://cs9-api.salesforce.com/ does yours have that?

  5. Dhan says:

    Yes too face the same issue with SFDC API query method
    Here the exception :

    UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService

    In my query request i couldn’t make out any field like service url or destination url.

    Any inputs will be appreciated.

    Thanks
    Dhan

  6. Pingback: Salesforce and soapUI – Using the default query method » Deadlypenguin

  7. pcon says:

    I’ve written a new post about how to fix that issue.

  8. Siddu says:

    Here is my code. Could you please let me know how to invoke this from soapUI or command prompt.

    When I try to call this from command prompt it is trowing an error that “Protocol https is not supported or disabled in libcurl”

    any help would be greatly appreciated.

    Thanks in advance.

    @RestResource(urlMapping=’/UpdateLead/*’)
    global class UpdateLeadRecord {
    @HttpPost
    global static boolean LeadRecordUpdateFromExSystem(String RecordId, String APIName, String FieldValue) {

    try
    {
    String LeadQuery = ‘Select id, ‘+ APIName + ‘ From Lead where id =: ‘+RecordId + ‘ limit 1′;

    Lead LeadRecord = Database.query(LeadQuery);

    //LeadRecord.APIName = FieldValue;

    //Object o = LeadRecord.get(APIName);
    LeadRecord.put(APIName, FieldValue);

    update LeadRecord;

    return true;
    }
    catch(Exception e)
    {
    return false;
    }

    }
    }

  9. pcon says:

    All the experience I have with soapUI is with SOAP webservices not with REST webservices. I would suggest posting your question / problem on either the Stackexchange site of the Salesforce developer forums.

  10. Pingback: SFDC inbound web service test with SOAPUI | SalesForce.com IQ

  11. rf says:

    I am not getting Login request under soapbindings to get the session id.

    i have only the wsdl imported into the project. Please help me where i am missing.

    I am testing the webservice part, so i wrote a sample webservice using develper edition.

    below is my webservice class

    global class test_websrvc{

    webservice static string test_web(String name){
    return ‘Hello’+name ;
    }

    }

  12. pcon says:

    Which WDSL are you using as your base?

  13. Jose Tlaseca says:

    Hello:

    Thanks for your post, it was very helpful.

    I have created a SOAP webservice. I need to expose that WS to a force.com site in order to make it public.

    How can I test it using SOAP UI? (There are no login and password)

  14. pcon says:

    This is an interesting problem. I’ll look into it and write a post specifically about using soapUI and WebServices exposed via site, but in the mean time you can probably glean enough information from here.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>