使用Kie .Net Adaptor时Drools未向C#桌面应用返回结果
Let's break down why you're getting a 200 status but empty response body, and fix this step by step:
1. Fix Your Execution Flow & Command Building
Looking at your code, you're calling Insert and FireAllRules before ExecuteAsync, but you need to ensure these methods are properly queuing commands to send to the Kie Server. Some implementations of the Kie .Net Adaptor require you to build all commands first, then send them in one ExecuteAsync call. Your current code might not be bundling these commands correctly, leading to the server executing an empty command set.
Here's a cleaned-up version of your button click handler to ensure commands are properly queued:
private async void Start_Click(object sender, EventArgs e) { // Initialize your Bilan object with trimmed input values Bilan b = new Bilan { maladie = maladieText.Text.Trim(), localisation = localisationText.Text.Trim(), organe = organeText.Text.Trim(), medicament = null }; // Configure the Kie Executer KieExecuter k = new KieExecuter { HostUrl = "http://localhost:8080/", AuthUserName = "kie-server", AuthPassword = "kie1234", LookUp = "defaultKieSession" }; // Queue commands: Insert the Bilan object, then fire all rules k.Insert(b, "pharmacie.projetpfe.Bilan"); k.FireAllRules(); // Execute the command set and get the response var response = await k.ExecuteAsync<Bilan>("ContainerTest"); // Properly access the medicament property (avoid using ToString() directly) if (response.SmartSingleResponse != null) { medicament.Text = response.SmartSingleResponse.medicament ?? "No matching medicament found"; } else { medicament.Text = "No response object returned"; } }
2. Verify Your Drools Rule Logic
A 200 status means the connection works, but if your rules aren't triggering or aren't updating the medicament property, you'll get an empty or unchanged object back.
Double-check your DRL rule:
- Ensure the fully qualified class name matches exactly (
pharmacie.projetpfe.Bilan) - Confirm rule conditions match input values (Drools runs on Java, which is case-sensitive—make sure property names like
maladie,localisationmatch exactly between your C# class and DRL) - Always use
update($bilan);in the rule'sthenblock to propagate changes back to the response.
Example valid DRL rule:
package pharmacie.projetpfe; rule "Assign Antibiotic for Lung Infection" when $bilan: Bilan( maladie == "Pneumonie", localisation == "Thorax", organe == "Poumons", medicament == null ) then $bilan.setMedicament("Amoxicilline"); update($bilan); // Critical to send the updated object back to the client end
3. Debug With Kie Server Logs
Check the Kie Server's logs (usually in wildfly/standalone/log/server.log if using WildFly) for:
- Errors related to object deserialization (e.g., "class not found" for
pharmacie.projetpfe.Bilan) - Rule firing events (look for lines like
Rule fired: AssignMedicament) - Warnings about missing session or container names
4. Validate Object Serialization
Ensure your C# Bilan class is properly serializable by adding the [Serializable] attribute:
[Serializable] public class Bilan { public string organe { get; set; } public string maladie { get; set; } public string localisation { get; set; } public string medicament { get; set; } }
This ensures the Kie .Net Adaptor can correctly serialize/deserialize the object to communicate with the server.
内容的提问来源于stack exchange,提问作者mohammed Nizar Ben Maallem

