Calling a decision service as a SOAP web service

Each deployed decision service can be invoked as a SOAP web service.

About this task

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

Procedure

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

Example

Here is how to retrieve the WSDL file from Rule Execution Server:
  1. Make sure you have deployed the rule project to the 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.
Here is how to generate the proxy classes with Apache Axis:
  1. Download and install the Eclipse IDE for Java™ EE Developers, which includes the Web Tools Platform (WTP) tool to generate the proxy classes for invoking the web service from a Java application.
  2. Run your Eclipse IDE for Java EE Developers and create a new Java Project ( File > New > Java Project) to host the proxy classes to be generated.
  3. Copy the WSDL file into this Java project.
  4. Click File > New > Other > Web Services > Web Service Client.
  5. In the Web Service Client wizard, click Next.
  6. For the service definition, browse to the WSDL file.
  7. Move the slider to select Develop client.
  8. 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.
  9. Click Finish.

Here is a Java code sample that imports the proxy classes generated with Apache Axis for the MiniloanService decision service and calls the service 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 <host> and <port>
		// NB: endpointURI is defined in the location attribute of the WDSL file
		String endpointURI = "http://<host>:<port>/DecisionService/ws/MiniloanService/MiniloanServiceRuleset/v75";

		MiniloanServiceRulesetDecisionServiceProxy proxy = new MiniloanServiceRulesetDecisionServiceProxy(endpointURI);
		
		MiniloanServiceMiniloanServiceRulesetBindingStub stub = (MiniloanServiceMiniloanServiceRulesetBindingStub)proxy.getMiniloanServiceRulesetDecisionService_PortType();
		
		// 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);						
		}
	}

}