PDA

View Full Version : how to write an httphander?



noeska
22-02-2009, 10:47 PM
On trying to write a httphandler with the delphi prism command line it get the following error:

C:\Projecten\Oxygene\MyHandler.pas(8,35) : Error : (PE66) Interface property g
etter not implemented for "System.Web.IHttpHandler.IsReusable"


This is the source:

unit MyHandler;

interface

uses System.Web;

type
HelloWorldHandler = public class(System.Object,IHttpHandler)
public
public function GetIsReuseable: boolean;
procedure ProcessRequest(context: HttpContext);
property IsReuseable: boolean read GetIsReuseable;
end;

implementation

function GetIsReuseable: boolean;
begin
Result := false;
end;

procedure HelloWorldHandler.ProcessRequest(context: HttpContext);
begin
context.response.Write('Hello World');
end;

end.


And this is how i compile:


Oxygene MyHandler.pas /assemblyname:MyHandler /type:library /frameworkfolder:C:\WINDOWS\Microsoft.NET\FrameWork \v2.0.50727 /ref:$(Framework)\System.Web.dll /ref:$(Framework)\System.dll



I also tried using get_IsReuseable instead of GetIsReuseable but that only leads to more errors ...

Thanks in advance for your help.

AthenaOfDelphi
23-02-2009, 06:55 AM
I'm not a .Net user, but standard Object Pascal syntax dictates you need 'HelloWorldHandler.' in front of methods belonging to the class. Your getIsReusable handler doesn't have that.

noeska
23-02-2009, 07:45 AM
You are right it should be there, but it does not solve the problem the same error message is stil there :( Also removing the double public declaration does not help either.

AthenaOfDelphi
23-02-2009, 07:53 AM
If that doesn't work, I'm sorry hon, I can help no more as I don't have access to Delphi Prism or any other .Net compiler.

noeska
23-02-2009, 08:41 AM
Dont feel bad about it. I should blame me for writing an half implementation.
With the classname in front of the funtion get_IsReuseable started to work also i added an constructor so the code now looks like this:


unit MyHandler;

interface

uses System.Web;

type
HelloWorldHandler = class(IHttpHandler)
public
constructor Create;
function get_IsReusable: Boolean;
property IsReusable: Boolean read get_IsReusable;
procedure ProcessRequest(context: HttpContext);
end;

implementation

constructor HelloWorldHandler.Create;
begin
inherited Create;
end;

function HelloWorldHandler.get_IsReusable: Boolean;
begin
Result := False;
end;

procedure HelloWorldHandler.ProcessRequest(context: HttpContext);
var
Response: HttpResponse;
Request: HttpRequest;
begin
Request := context.Request;
Response := context.Response;
Response.Write('<html>');
Response.Write('<body>');
Response.Write('<h1>Hello from a synchronous custom HTTP handler written in
Delphi Prism.</h1>');
Response.Write('</body>');
Response.Write('</html>');
end;

end.


And compiles with this:


Oxygene MyHandler.pas /assemblyname:MyHandler /type:library /frameworkfolder:C:\WINDOWS\Microsoft.NET\FrameWork \v2.0.50727 /ref:$(Framework)\System.Web.dll /ref:$(Framework)\System.dll



And in web.config the following should be added to the httphandlers:

<add verb="*" path="*.sample" type="MyHandler.HelloWorldHandler,MyHandler"/>


So http://localhost/test/test.sample shows Hello from a synchronous custom HTTP handler written in Delphi Prism.

_________________________________________________

I use the free command line edition of Delphi Prism which can be downloaded for free at: http://cc.codegear.com/Free.aspx?id=26256