Search code examples
delphiwebworkflowintraweb

IntraWeb EOSError 1400


I'm trying to create a website containing TMS workflows. I stuck on EOSError 1400 problem when trying to execute workflow. Workflow is started on a button click and than goes to WorkflowStudio1TaskCreated procedure and continues to WorkflowStudio1SendMail. Then it crashes with error mentioned above. What I'm doing wrong?

EOSError 1400

Unit Code:

unit Unit1;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWColor, IWTypes,
  Data.DBXFirebird, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error,
  FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool,
  FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.FB, FireDAC.Phys.FBDef,
  FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
  FireDAC.DApt, Vcl.Controls, IWVCLBaseControl, IWBaseControl,
  IWBaseHTMLControl, IWControl, IWCompButton, Data.DB, FireDAC.Comp.DataSet,
  FireDAC.Comp.Client, Data.SqlExpr, wsDB, wsDbx, wsClasses, wsMain;

type
  TIWForm1 = class(TIWAppForm)
    WorkflowStudio1: TWorkflowStudio;
    WorkflowDBXDB1: TWorkflowDBXDB;
    SQLConnection1: TSQLConnection;
    FDConnectionTMS: TFDConnection;
    FDQueryGET: TFDQuery;
    FDQueryUPDADTE: TFDQuery;
    FDConnectionMedusa: TFDConnection;
    FDQueryGetUsers: TFDQuery;
    FDQueryUsers: TFDQuery;
    FDConnectionUPRO: TFDConnection;
    FDQueryGetUser: TFDQuery;
    qryInsertObject: TFDQuery;
    qryGetZapoUsers: TFDQuery;
    qryGetMedusaUsers: TFDQuery;
    qryGetEmail: TFDQuery;
    IWButton1: TIWButton;
    procedure IWButton1Click(Sender: TObject);
    procedure WorkflowStudio1TaskCreated(Sender: TObject;
      ATaskIns: TTaskInstance);
    procedure WorkflowStudio1SendMail(Sender: TObject; TaskIns: TTaskInstance;
      AUser: TWorkflowUser; AEmailInfo: TEmailInformation; var Sent: Boolean);
  public
  end;

implementation

{$R *.dfm}


procedure TIWForm1.IWButton1Click(Sender: TObject);
var
  Wrkins : TWorkflowInstance;
  t : TTaskInstance;
begin
  WorkflowStudio1.UserManager.Users.Add('1', 'Someone', '[email protected]');
  Wrkins := WorkflowStudio1.WorkflowManager.CreateWorkflowInstanceByName('Temp');

  Wrkins.Diagram.Variables.FindByName('User').Value := WorkflowStudio1.UserManager.Users.FindById('1').UserName;

  WorkflowStudio1.WorkflowEngine.RunWorkflow(Wrkins);
end;


procedure TIWForm1.WorkflowStudio1SendMail(Sender: TObject;
  TaskIns: TTaskInstance; AUser: TWorkflowUser; AEmailInfo: TEmailInformation;
  var Sent: Boolean);
begin
  WebApplication.ShowMessage('send mail');
  Sent := True;
end;

procedure TIWForm1.WorkflowStudio1TaskCreated(Sender: TObject;
  ATaskIns: TTaskInstance);
begin
  WebApplication.ShowMessage('Task ' + ATaskIns.Key + ' created');
end;

initialization
  TIWForm1.SetAsMainForm;

end.

ServerControl:

unit ServerController;

interface

uses
  SysUtils, Classes, IWServerControllerBase, IWBaseForm, HTTPApp,
  // For OnNewSession Event
  UserSessionUnit, IWApplication, IWAppForm, IW.Browser.Browser;

type
  TIWServerController = class(TIWServerControllerBase)
    procedure IWServerControllerBaseNewSession(ASession: TIWApplication);

  private

  public
  end;


  function UserSession: TIWUserSession;
  function IWServerController: TIWServerController;

implementation

{$R *.dfm}

uses
  IWInit, IWGlobal;

function IWServerController: TIWServerController;
begin
  Result := TIWServerController(GServerController);
end;



function UserSession: TIWUserSession;
begin
  Result := TIWUserSession(WebApplication.Data);
end;

procedure TIWServerController.IWServerControllerBaseNewSession(
  ASession: TIWApplication);
begin
  ASession.Data := TIWUserSession.Create(nil, ASession);
end;


initialization
  TIWServerController.SetServerControllerClass;
end.

And in UserSessionUnit nothing is added


Solution

  • Just do not try to put everything into the web application. Instead you can create a single-threaded / single-user VCL or console application which hosts the TMS workflow component, and which communicates with the Intraweb process over some inter process communication (IPC) interface.

    This is a common approch for complex web applications, which also use asynchronous processing instead of doing everything within the context of a HTTP request.

    Read for example: Dopplr: - It's made of messages (slideshare presentation)