Handling irServer SOAP Endpoint Error Conditions

  • Updated

irServer Rule Execution Service SOAP Endpoint uses different error reporting mechanisms depending on the type of error encountered on the server.

Normally any error conditions or exceptions encountered on the server are reported to the client via the WCF Fault mechanism.  These will likely occur during RuleApplication compilation or erroneous state modifications.  Runtime errors, however, are generally large in size due to the embedded RuleExecutionLog, RuleSessionState and AggExecStats; these return to the client as a regular service response, but the response is flagged as having runtime errors.

When using a ServiceReference proxy client, you should always look for runtime errors. Check the RuleEngineServiceResponse.HasRuntimeErrors property after each request to determine whether the attached RuleExecutionLog contains errors.

The following code snippets from the irServer Rule Execution Service Samples illustrate how the different error conditions can be detected:

Creating an Invalid Entity

try
{
 // Ask the RuleEngineService for its associated Repository Service URI
 Console.WriteLine("- Requesting RespitoryServiceUri from RuleEngineService...");
 string repositoryServiceUri = proxy.GetRuleRepositoryServiceUri();
 if (String.IsNullOrEmpty(repositoryServiceUri))
 {
         throw (new Exception("RuleEngineService is not configured to use a specific Repository Service."));
 }
 // Get RuleApp as defined in the config (RepositoryRuleApp or FileSystemRuleApp)
 RuleApp ruleApp = GetRuleApp(repositoryServiceUri);
 // Construct a request that will fail with an Exception
 ApplyRulesRequest request = new ApplyRulesRequest();
 request.RuleApp = ruleApp;
 request.EntityName = "InvalidEntityName123"; // Use an invalid Entity name
 request.RuleEngineServiceOutputTypes = new RuleEngineServiceOutputTypes();
 request.RuleEngineServiceOutputTypes.ActiveNotifications = true;
 request.RuleEngineServiceOutputTypes.ActiveValidations = true;
 request.RuleEngineServiceOutputTypes.EntityState = true;
 request.EntityState = "<InvalidEntityName123/>";
 Console.WriteLine("- Calling ApplyRules() from RuleEngineService...");
 Console.WriteLine("");
 proxy.ExecuteRuleEngineRequest(request); // This should throw a contracted Fault
}
catch (FaultException<ServiceFault> contractedFault)
{
 Console.WriteLine("Received expected contracted fault:");
 Console.WriteLine("Exception Type:" + contractedFault.Detail.QualifiedName);
 Console.WriteLine("Exception Message:" + contractedFault.Detail.Message);
}

Handling a Runtime Error

// Get RuleApp designed to fail at Runtime
RuleApp ruleApp = GetDivideByZeroRuleApp();
// Construct a request that will fail *without* throwing an Exception
ApplyRulesRequest request = new ApplyRulesRequest();
request.RuleApp = ruleApp;
request.EntityName = "Entity1"; // Use an invalid Entity name
request.RuleEngineServiceOutputTypes = new RuleEngineServiceOutputTypes();
request.RuleEngineServiceOutputTypes.EntityState = true;
request.EntityState = "<Entity1/>";
Console.WriteLine("- Calling ApplyRules() from RuleEngineService...");
Console.WriteLine("");
// This should succeed, but the response should have a RuntimeError flag set to true
RuleEngineServiceResponse response = proxy.ExecuteRuleEngineRequest(request);
if (response.HasRuntimeErrors)
{
 // Iterate all the Runtime errors in the Execution Log
 foreach (RuleExecutionLogMessage msg in response.RuleExecutionLog.Messages)
 {
         if (msg is ErrorMessage)
         {
                 ErrorMessage error = (ErrorMessage)msg;
                 Console.WriteLine("Expected RuntimeError: " + error.Message);
         }
 }
}

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.