2011-12-05 100 views
3

我在德尔福XE2保持SOAP服务器(含THTTPSoapDispatcherTHTTPSoapPascalInvoker一个TWebModuleTWSDLHTMLPublish),我不能找到一种方法,处理一个EIDSocketError(不在调试模式!)。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]

“返回从年龄。

事实证明,这是德尔福及其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; 

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

如果我声明的onException的我WebModule,我可以记录异常,但无论我如何努力处理/释放它,它仍然显示弹出:

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]

仍在试图后来找到一个解决方案几个月,没人知道?我厌倦了这个德尔福的侵入性和累赘的错误,因为它可以是这样的!

+0

代码非常重,至少我必须提供哪些部分? – Darkendorf

+1

不要在handleExceptio()或OnException中释放异常。它将被调用OnException的异常处理程序释放。 –

+0

谢谢,我删除了这部分(但事实上我甚至不能记录错误,所以我不会输入所有的OnError事件函数...) – Darkendorf

回答

2

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

+0

我该怎么做,因为indy引发错误本身并显示立即弹出一个窗口,在10之后隐藏应用程序 - 或者弹出窗口显示?如果我可以阻止它显示弹出窗口,它可能没有什么坏处......无论如何,感谢您阅读我^^ – Darkendorf

+0

对不起,应用程序不是特技,但它不能接受更多的连接 – Darkendorf

+0

如果没有更多的的情况下,那么我必须指向2号......我在哪里必须搜索那些“默认异常处理程序”? – Darkendorf