You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Kie .Net Adaptor时Drools未向C#桌面应用返回结果

Troubleshooting Empty ResponseBody When Calling Drools via Kie .Net Adaptor in C# WinForms

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, localisation match exactly between your C# class and DRL)
  • Always use update($bilan); in the rule's then block 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:23:46