Using a SOAP web service

A client application can invoke a decision service ruleset as a SOAP web service.

Before you begin

The client application must pass authentication credentials for the cloud portal (see Authentication for REST and SOAP invocation).

Note: Operational Decision Manager on Cloud supports SOAP 1.1. It does not support later versions of SOAP.

About this task

For a client application to invoke a decision service ruleset as a SOAP web service, you must create proxy classes from a Web Services Description Language (WSDL) file generated for the ruleset path. The format of a WSDL file is independent of the language that generates it.

Procedure

  1. Obtain a WDSL file for a decision service ruleset.
  2. Generate proxy classes from the WSDL file.
  3. Use the proxy classes to invoke the ruleset from your client application.

Example

To get a WSDL file from Rule Execution Server:
  1. Deploy the ruleset to Rule Execution Server.
  2. In the Rule Execution Server console, go to the Explorer tab.
  3. In the Navigator pane, click a RuleApp, and then click the ruleset that corresponds to your decision service.
  4. In the ruleset view, click Retrieve HTDS Description File.
  5. Select SOAP as the service protocol type.
  6. Check Latest ruleset version and Latest RuleApp version to generate the WSDL file for the latest versions.
  7. Click Download.
For this procedure, you must have Eclipse IDE for Jakarta EE Developers installed on your computer. It includes the Web Tools Platform to generate the proxy classes for invoking the web service from a Java™ application. To generate the proxy classes with Apache Axis:
  1. Start Eclipse IDE for Jakarta EE Developers and create a new Java Project ( File > New > Java Project) to host the proxy classes.
  2. Copy the WSDL file into this Java project.
  3. Click File > New > Other > Web Services > Web Service Client.
  4. In the Web Service Client wizard, click Next.
  5. For the service definition, browse to the WSDL file.
  6. Move the slider to select Develop client.
  7. Under Configuration, ensure Apache Axis is selected as the Web service runtime, and then select the Java project as the Client project where you want to host the proxy classes that are generated.
  8. Click Finish.
The following Java code sample imports the proxy classes for MiniloanServiceRuleset and calls the ruleset from a Java application:
import com.ibm.www.rules.decisionservice.MiniloanService.MiniloanServiceRuleset.MiniloanServiceMiniloanServiceRulesetBindingStub;
import com.ibm.www.rules.decisionservice.MiniloanService.MiniloanServiceRuleset.MiniloanServiceRulesetDecisionServiceProxy;
import com.ibm.www.rules.decisionservice.MiniloanService.MiniloanServiceRuleset.MiniloanServiceRulesetRequest;
import com.ibm.www.rules.decisionservice.MiniloanService.MiniloanServiceRuleset.MiniloanServiceRulesetResponse;
import com.ibm.www.rules.decisionservice.MiniloanService.MiniloanServiceRuleset.param.Borrower;
import com.ibm.www.rules.decisionservice.MiniloanService.MiniloanServiceRuleset.param.Loan;


public class DecisionServiceExecution {

	public static void main(String[] args) {
		
		// Replace <vhostname> with the name of the host of the Cloud portal
		// NB: endpointURI is defined in the location attribute of the WDSL file
		String endpointURI = "https://<vhostname>.bpm.ibmcloud.com/odm/dev/DecisionService/ws/MiniloanService/MiniloanServiceRuleset/v75";

		MiniloanServiceRulesetDecisionServiceProxy proxy = new MiniloanServiceRulesetDecisionServiceProxy(endpointURI);
		
		MiniloanServiceMiniloanServiceRulesetBindingStub stub = (MiniloanServiceMiniloanServiceRulesetBindingStub)proxy.getMiniloanServiceRulesetDecisionService_PortType();
	
		// Replace "loginID" with the functional ID of the service account you are using to authenticate with your tenant in the Cloud
		stub.setUsername("loginID");
		
		// Replace "password" with the password of the service account you are using to authenticate with your tenant in the Cloud
		stub.setPassword("password");
		
		// Set the borrower
		com.ibm.www.rules.decisionservice.MiniloanService.MiniloanServiceRuleset.Borrower borrower = 
				new com.ibm.www.rules.decisionservice.MiniloanService.MiniloanServiceRuleset.Borrower(
						"John", // name
						600, // credit score
						80000); // yearlyIncome
		
		Borrower borrowerParam = new Borrower(borrower);
		
		// Set the loan
		com.ibm.www.rules.decisionservice.MiniloanService.MiniloanServiceRuleset.Loan loan = 
				new com.ibm.www.rules.decisionservice.MiniloanService.MiniloanServiceRuleset.Loan(
						500000, // amount
						240, // duration
						0.05, // yearlyInterestRate
						0, // yearlyRepayment (to be computed by the decision service)
						true, // approved (set to true by default, to be computed by the decision engine),
						null); // messages (to be computed by the decision service)
		
		Loan loanParam = new Loan(loan);
		
		// Set the decision ID
		String decisionID = "1";
				
		MiniloanServiceRulesetRequest request = new MiniloanServiceRulesetRequest(decisionID, borrowerParam, loanParam);
		
		try {
			MiniloanServiceRulesetResponse response = proxy.miniloanServiceRuleset(request);
			System.out.println("Rules executed.");
			System.out.println("Approved: " + response.getLoan().getLoan().isApproved());
			System.out.println("Yearly interest rate: " + response.getLoan().getLoan().getYearlyInterestRate());
			System.out.println("Yearly repayment: " + response.getLoan().getLoan().getYearlyRepayment());
			String[] messages = response.getLoan().getLoan().getMessages();
			if (messages != null) {
				System.out.println("Messages: ");
				for (String message : messages) {
					System.out.println(message);
				}
			}
		}
		catch (Exception e) {
			throw new RuntimeException("An error occurred when invoking Decision Service at: "
										+ endpointURI, e);						
		}
	}

}