发布模式下的EIdSocketError

时间:2011-12-05 15:24:19

标签: delphi exception delphi-xe2 webrequest indy

我正在维护一个 SOAP 服务器( TWebModule 包含 THTTPSoapDispatcher THTTPSoapPascalInvoker delphi-XE2 中的TWSDLHTMLPublish ,我找不到处理 EIDSocketError 的方法(不在调试模式下!)。

我甚至不确定它从哪里开始......我知道它是在用户在等待服务器响应(请求超时或客户端网络丢失)的情况下断开连接后引发的。

它肯定是由 IdHTTPWebBrokerBridge 组件引发的,所以我试图从myIdHTTPWebBrokerBridge.OnException处理它而没有成功。我在这里和那里读到它在调试模式中被提升但可以避免,但无法找到如何在发布模式下处理它甚至防止它被提升的线索......

如果需要,我可以在我的应用程序的请求部分提供代码。

MyService.exe

program MyService;
{$APPTYPE GUI}


{$R 'documents.res' 'documents.rc'}

uses
  Forms,
  Sysutils,
  WebReq,
  IdHTTPWebBrokerBridge,
  UFMyService in 'Unit\UFMyService.pas' {FMyService},
  UWMMyService in 'Unit\UWMMyService.pas' {WMMyService: TWebModule},
  UDMMyService in 'Unit\UDMMyService.pas' {DMMyService: TDataModule},
  UIMyService in 'Unit\UIMyService.pas',
  UCMyService in 'Unit\UCMyService.pas',
  superobject in 'Unit\superobject.pas',
  superxmlparser in 'Unit\superxmlparser.pas',


{$R *.res}
const
  se = '/';
begin
  if WebRequestHandler <> nil then
    WebRequestHandler.WebModuleClass := WebModuleClass;
  Application.Initialize;
  Application.Title := 'My Service';
  try
    Application.CreateForm(TFMyService, FMyService);
    Application.Run;
  Except on E:Exception do
    begin
      Log('!! Exception au lancement : '+E.Message);
      Application.Terminate;
    end;
  end;
end.

然后在

UFMyService.pas

unit UFMyService;

interface

uses (...)

type
  TFMyService = class(TForm)
    ApplicationEvents1: TApplicationEvents;
    procedure FormCreate(Sender: TObject);
    procedure ApplicationEvents1Exception(Sender: TObject; E: Exception);
(...)
  private
    FServer: TIdHTTPWebBrokerBridge;
    procedure handleException(AContext: TIdContext; AException: Exception);
(...)
  end;

var
  FMyService: TFMyService;

implementation

{$R *.dfm}

uses
  UWMMyService, UDMMyService, (...);

procedure TFMyService.ApplicationEvents1Exception(Sender: TObject; E: Exception);
begin
  if not(E is EIdConnClosedGracefully) and not (E is EIdConnClosedGracefully) then
  begin
    Log(e.Message);
  end;
end;

procedure TFMyService.FormCreate(Sender: TObject);
begin
  (...)
  FServer := TIdHTTPWebBrokerBridge.Create(Self);
  FServer.OnException := handleException;
  (...)
end;

procedure TFMyService.handleException(AContext: TIdContext; AException: Exception);
begin
  if not(AException is EIdSilentException) and not(AException is EIdConnClosedGracefully) then
  begin
    Log(AException.Message);
  end;
end;

[edit]

'从岁月开始。

事实证明,这是显示弹出窗口的delphi及其TWebRequestHandler:

procedure TWebRequestHandler.HandleException(Sender: TObject);
var
  Handled: Boolean;
  Intf: IWebExceptionHandler;
begin
  Handled := False;
  if ExceptObject is Exception and
    Supports(Sender, IWebExceptionHandler, Intf) then
    try
      Intf.HandleException(Exception(ExceptObject), Handled);
    except
      Handled := True;
      System.SysUtils.ShowException(ExceptObject, ExceptAddr);
    end;
  if (not Handled) then
    System.SysUtils.ShowException(ExceptObject, ExceptAddr);
end;

我只是不知道如何处理异常...

如果我声明我的WebModule的OnException,我可以记录异常,但无论我如何尝试处理/释放它,它仍然显示弹出窗口:

procedure TWMMyService.WebModuleException(Sender: TObject; E: Exception;
  var Handled: Boolean);
var
  AnError : TObject;
begin
  Log('!! WebModule Error ('+Sender.ClassName+')');
  Log('!! Type : '+E.ClassName);
  Log('!! Message : '+E.Message);
  Handled:=True;
// later add-on
  if( E is EIdSilentException) then
  begin
    //Socket 10054 Connection reset by peer.
    //etc...
    AnError := AcquireExceptionObject;
    if (AnError <> nil) then
    begin
      Log('!! Ignore Exception');
      ReleaseExceptionObject;
    end;
  end; // then the popup appears...
end;
到达

Log('!! Ignore Exception');,但ReleaseExceptionObject无效;也许为时已晚。

我将WebRequestHandler.MaxConnections更改为100,以防止客户端被这些套接字异常过快地阻止,但想象必须验证100个弹出窗口以继续工作......我只是不能这样离开^^

感谢所有建议/建议/解决方案:)

[edit]

几个月后仍然试图找到解决方案,没有人知道?我厌倦了这个Delphi侵入性和累人的错误,因为它可能不过是这个!

1 个答案:

答案 0 :(得分:3)

为什么你需要处理异常? EIdSocketError表示发生套接字错误。有可能连接丢失或关闭不正确。 Indy服务器端连接是多线程的。套接字错误意味着套接字可能处于不稳定状态并需要关闭。让Indy在内部处理异常会停止连接的拥有线程并为你关闭套接字。

相关问题