Call an External SOAP Web Service from Groovy When No Security Scheme Is Required

This example shows how to create a connection to an external SOAP web service on the Internet and call the web service from a Groovy script used in Application Composer. The web service isn't secured.

For this example, the web service is used to calculate a custom field's default value.

The following table summarizes key decisions for this scenario:

Decisions to Consider

In This Example

What name will you use for the web service connection?

mathsws

What is the URL of the Web Services Description Language (WSDL) file that you will use?

http://external-hosted:7101/MathsWS-Model-context-root/NoSecurity?wsdl

Note: The URL shown here's an arbitrary example. You must obtain the real WSDL URL from the service provider.

Where will the web service be called from?

From a Groovy script expression used to calculate a custom field's default value.

Which web service method will be called from the Groovy script?

getSum

This method returns the sum of two integer argument values.

To call a web service from a Groovy script when no security scheme is required, complete the following tasks:

  1. Create the web service connection.

  2. Add the web service call to the Groovy script, and verify that the call succeeds.

Prerequisites

Verify that you have completed the following prerequisite steps:

  1. Get details of the WSDL URL to use from the web service provider.

  2. Create a custom field for an object that has a calculated default value.

  3. Prepare the Groovy script for the expression used to calculate the field's default value. The Groovy code must prepare the argument values, which in this example are two values that are summed.

Creating the Web Service Connection

When you create a web service connection, you specify a name for the web service, the URL of the WSDL file, and the security scheme settings. The name is simply an identifier that's used in the list of web services in the Expression Builder in Application Composer.

  1. In Application Composer, select Web Services in the Common Setup pane.

  2. On the Web Services page, click the New icon, then click SOAP.

  3. On the Create SOAP Web Service Connection page, enter mathsws in the Name field.

    The name must not include periods.

  4. Enter http://external-hosted:7101/MathsWS-Model-context-root/NoSecurity?wsdl in the WSDL URL field, and click Read WSDL.

    After you click Read WSDL. the Service and Port fields are filled according to values in the WSDL file. Under Security Scheme, the None radio button becomes enabled and selected.

  5. Click Save and Close.

    The web service connection is created and the name and WSDL URL are listed on the Web Services page.

Adding the Web Service Call to the Groovy Script

In the Expression Builder dialog that you see when you create or edit Groovy scripts, there is a Web Services tab that lists the web services for which you have created a connection. For each web service you can include calls to the available methods in your Groovy script.

  1. In Application Composer, edit the custom field that uses the expression that will contain the web service call.

  2. Click the Expression Builder icon.

  3. In the Expression Builder dialog, select the Web Services tab.

  4. Select mathsws from the Web Services list.

  5. Select getSum from the Functions list.

  6. Position the cursor at the place in the script where you want to insert the web service call.

  7. Click Insert to insert the code to call the web service method.

  8. Update the script so that two integer values are provided as arguments for the web service call.

  9. Click Submit.

  10. Verify that the web service call succeeds; in this example the custom field should have the expected default value.